Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set max rows 4 and columns to be dynamic in RecyclerView GridLayoutManager

I want a grid view which adds elements in new row each time when the row count reach 4 it should start adding element in 1st row.

Let say I have 7 items in 1st image and add 2 more elements then it should add first element at last index of 2nd column and second element at 1 index of column 3

Let say I have 11 items in 2nd image and add 2 more elements then it should add first element at last index of 3rd column and second element at 1 index of column 4

enter image description here

enter image description here

like image 683
Vishal Avatar asked Sep 19 '25 01:09

Vishal


1 Answers

Try this:

        GridLayoutManager layoutManager = 
                   new GridLayoutManager(getActivity(), 4);
            layoutManager.setOrientation(RecyclerView.HORIZONTAL);
            recyclerView.setLayoutManager(layoutManager);
like image 60
bhaskar kurzekar Avatar answered Sep 20 '25 15:09

bhaskar kurzekar