Is it possible to create a Horizontal Android ListView?

3

Problem

I need to implement a horizontal ListView to create a horizontal navigation bar on my Product Gallery in my Sales Catalog. With the intention of making the navigation more intuitive and easy on the part of the users.

But to my surprise it seems to me that ListView does not support horizontal navigation.

Desired implementation (To better understand the scenario)

My solution using ListView horizontal would put it on my gallery (with RelativeLayout ), and populate it with thumbnails of the images of the Catalog products, thus allowing navigation through it, as well as scroll horizontal over the gallery.

Questions?

  • Is there any way to make ListView horizontal?
  • Is there any better way to solve my problem without using ListView ;

Additional information

I'm using to deploy my gallery this library .

    
asked by anonymous 25.07.2014 / 14:33

1 answer

3

I used this api in design and it worked fine

Link to download: link

Your activity stays that way

public class HorizontalListViewDemo extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.listviewdemo);

    HorizontialListView listview = (HorizontialListView) findViewById(R.id.listview);
    listview.setAdapter(mAdapter);

}

private static String[] dataObjects = new String[]{ "Text #1",
    "Text #2",
    "Text #3" }; 

private BaseAdapter mAdapter = new BaseAdapter() {

    @Override
    public int getCount() {
        return dataObjects.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View retval = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem, null);
        TextView title = (TextView) retval.findViewById(R.id.title);
        title.setText(dataObjects[position]);

        return retval;
    }

};

}

Your layout looks like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="#fff"
 >

  <com.devsmart.android.ui.HorizontialListView
     android:id="@+id/listview"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
     android:background="#ddd"
  />

 </LinearLayout>

Custom ListItem looks like this

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="#fff"
   >

  <ImageView
      android:id="@+id/image"
      android:layout_width="150dip"
      android:layout_height="150dip"
      android:scaleType="centerCrop"
      android:src="@drawable/icon"
     />

      <TextView
      android:id="@+id/title"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textColor="#000"
      android:gravity="center_horizontal"
      />

 </LinearLayout>
    
28.07.2014 / 14:25