Horizontal Listview in Android

Horizontal ListView in Android?

As per Android Documentation RecyclerView is the new way to organize the items in listview and to be displayed horizontally

Advantages:

  1. Since by using Recyclerview Adapter, ViewHolder pattern is
    automatically implemented
  2. Animation is easy to perform
  3. Many more features

More Information about RecyclerView:

  1. grokkingandroid.com
  2. antonioleiva.com

Sample:

survivingwithandroid.com

Just add the below block to make the ListView to horizontal from vertical

Code-snippet

LinearLayoutManager layoutManager= new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(layoutManager);

How to create a horizontal list view? Android

If you want to create horizontal list you can use:

1)RecyclerView with GridLayoutManager.HORIZONTAL or LinearLayoutManager.HORIZONTAL

2) HorizontalVariableListView

How to build a horizontal ListView with RecyclerView

Is there a better way to implement this now with RecyclerView now?

Yes.

When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would.

To create a horizontal list with RecyclerView, you might do something like this:

LinearLayoutManager layoutManager
= new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false);

RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);

How to create an Horizontal List View inside of a Vertical List View?

Use a RecyclerView with Horizontal LinearLayout as a item view of vertical RecyclerView with Vertical LinearLayoutManager. Yeah if you are creating your views right now from the scratch, always use Recycler View instead of ListView onwards.



Related Topics



Leave a reply



Submit