Expandable RecyclerView-Horizontal Recyclerview Expand Vertically

DWQA QuestionsCategory: android questionExpandable RecyclerView-Horizontal Recyclerview Expand Vertically
kamal bunkar Staff asked 1 year ago

How to create auto expandable recyclerview? I have a horizontal Recyclerview, I need it to be expand vertically if more child item add into the RecyclerView at run time.
I how set recyclerview param property as horizontal but it is a single line horizontal list. It is not expanding vertically when item become more then the width of the mobile screen..
expandable recyclerview

1 Answers
kamal bunkar Staff answered 1 year ago

You generally see Recyclerview as a horizontal list or vertical list. To make it horizontal we set recyclerview param property as linearLayout property. The behavior of Horizontal Recyclerview that can expand vertically is called staging.

So if you want recyclerview expand itself vertical when item reaches at the end of screen width then you have to use staggeredGridLayoutManager. Define you recyclerview as

recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
// Here 4 is no. of columns to be displayed