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:
- Since by using Recyclerview Adapter, ViewHolder pattern is
automatically implemented - Animation is easy to perform
- Many more features
More Information about RecyclerView
:
- grokkingandroid.com
- 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 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 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 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
Location Needs to Be Enabled for Bluetooth Low Energy Scanning on Android 6.0
Ontaskremoved() Not Getting Called in Huawei and Xiaomi Devices
Android Broadcast Receiver Bluetooth Events Catching
Launch Activities from Different Package
How to Simulate Touch from Background Service with Sendevent or Other Way
Show Download Progress Inside Activity Using Downloadmanager
Android: Scrollview Force to Bottom
Start Application Knowing Package Name
What Will Happen to the Sharedpreferences on Update an Android App
Android:Static Fields and Memory Leaks
How to Create a Custom Notification Layout in Android
Send Data Back to the Script Which Started the Activity via Adb Shell Am Start
Ripple Effect on Android Lollipop Cardview
Mediaplayer Stutters at Start of Mp3 Playback
How to Customize Item Background and Item Text Color Inside Navigationview