Is it possible to create a Listview Android Horizontal?

Asked

Viewed 1,426 times

3

Problem

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

But to my surprise it seems that the ListView has no horizontal navigation support.

Intended implementation (To better understand the scenario)

My solution using ListView horizontal would put it over my gallery (with RelativeLayout), and populate it with miniature images of Catalogo products, thus allowing navigation through it, in addition to the scroll horizontal over the gallery.

Questions?

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

Additional information

I’m using to implement my gallery this library.

  • I recommend using the Horizontalvariablelistview library. I suggest searching github for the library repository.

  • You’ve used this library?

  • I use this library yes. I used to use the Twowaygridview library before, but now I’m using this one. Still supported and performing better. @Fernando

  • The most recommended is to use Recycler View In this answer you can see how to implement correctly https://stackoverflow.com/a/45953855/7069639

1 answer

3


I used this api in design and it worked cool

Link to download: http://www.dev-smart.com/archives/34

Your Easter looks like this

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>

Listitem to customize 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>
  • Here’s a tutorial explaining http://www.dev-smart.com/archives/34

  • 1

    Hello @Igorronner. Can you improve your answer so you can understand without relying on external links?

  • @gpupo, how do I edit my answer?

  • At the end of the reply there is a link editar

  • @Igorronner, I’m using a variation I found of your link, which is that one, I’m trying to resolve some limitations like centering the view center in case there are few items (Today is always getting aligned left no matter what I do). But it seems to me to be a limitation of Listview itself as it is open in that matter

  • This alignment issue you fix in the Item View.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.