Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recycler View Horizontal Scroll with 2 columns

Here is I have I have tried so far

LinearLayoutManager layoutManager =
        new GridLayoutManager(getActivity(), 2, GridLayoutManager.HORIZONTAL, false);

but It showed 2 rows instead of two columns.

How can I show two items with horizontal scroll with recycler view?

like image 834
Chhorn Soro Avatar asked Nov 15 '17 06:11

Chhorn Soro


People also ask

Is recycler view scrollable?

To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .

What is LinearLayoutManager Android?

This wear-specific implementation of LinearLayoutManager provides basic offsetting logic for updating child layout. A RecyclerView. LayoutManager implementation which provides similar functionality to android. widget. ListView .


1 Answers

Alright here is a funda,

When you are using GridLayoutManager.HORIZONTAL, second parameter will be considered as number of rows

while, when you write GridLayoutManager.VERTICAL second parameter will be considered as number of columns

Also, this

LinearLayoutManager layoutManager =
        new GridLayoutManager(getActivity(), 2, GridLayoutManager.HORIZONTAL, false);

supposed to be,

GridLayoutManager layoutManager =
            new GridLayoutManager(getActivity(), 2, GridLayoutManager.HORIZONTAL, false);

in above code, 2 is considered as number of rows to be generated.

like image 72
Paresh P. Avatar answered Oct 06 '22 21:10

Paresh P.