Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a horizontal ListView with RecyclerView

I need to implement a horizontal listview in my Android application. I did a bit of research and came across How can I make a horizontal ListView in Android? and Horizontal ListView in Android?. However, these questions were asked before Recyclerview was released. Is there a better way to implement this now with Recyclerview?

like image 270
Andre Perkins Avatar asked Feb 11 '15 17:02

Andre Perkins


People also ask

How do I make my recycler view horizontal Kotlin?

To implement a horizontal recycler view, create an instance of LinearLayoutManager with orientation HORIZONTAL and assign it to the recycler view. The below code would make the Recyclerview to show the elements in HORIZONTAL orientation.

How do you make a page indicator for horizontal RecyclerView?

You can add an indicator by using RecyclerView. ItemDecoration. Just draw some lines or circles at the bottom and use layoutManager. findFirstVisibleItemPosition() to get the current active item.

What is LinearLayoutManager Android?

LayoutManager implementations that lays out items in a grid. WearableLinearLayoutManager. This wear-specific implementation of LinearLayoutManager provides basic offsetting logic for updating child layout. A RecyclerView. LayoutManager implementation which provides similar functionality to ListView .

How do I create a horizontal list with a recyclerview?

When you use a RecyclerView, you need to specify a LayoutManagerthat is responsible for laying out each item in the view. The LinearLayoutManagerallows you to specify an orientation, just like a normal LinearLayoutwould. To create a horizontal list with RecyclerView, you might do something like this:

What is the difference between list view and recycler view?

Recycler view is more advanced version of list view and it works based on View holder design pattern. Using recycler view we can show grids and list of items. This example demonstrate about how to build a horizontal list view with Recycler View by creating a beautiful student records app that displays student name with age.

What is recyclerview in Android?

Android | Horizontal RecyclerView with Examples Last Updated: 16-12-2019 RecyclerView is a ViewGroup added to the android studio as a successor of the GridView and ListView. It is an improvement on both of them and can be found in the latest v-7 support packages.

How to add recycler view&card view in Android Studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Open build.gradle and add Recycler view & Card view library dependencies. Step 3 − Add the following code to res/layout/activity_main.xml.


2 Answers

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); 
like image 106
Bryan Herbst Avatar answered Sep 20 '22 11:09

Bryan Herbst


 <android.support.v7.widget.RecyclerView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="horizontal"         app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> 
like image 23
boiledwater Avatar answered Sep 22 '22 11:09

boiledwater