In GridLayoutManager i am able to set span count and that makes the items inside the view to resize to be able to fit that span count horizontally.
I have a LinearLayoutManager and i want to use it the same way, have a fixed number of items visible and resize them to fit.
I use both linear and grid on same view and shows items depending of the screen size. I can't seem to find a way to get both layouts showing the same amount of items.
Here is the kotlin version of Mihail Ignatiev's Answer
UPDATED
My previous answer was to use ItemsAdapter to set each items width, from the code design stand point this is not the best solution. Proper way to do that is to extend LinearLayoutManager, since it is LayoutManager responsibility to layout item views.
Gist: https://gist.github.com/modjke/b652021679a2ed1935645a18102ab799
Code:
}
PREVIOUS ANSWER
You can set exact item count in your adapter by providing a width for each item. This works only if all your items have equal width, do not forget to set
on your RecyclerView
I know this was asked a while ago, but I've found a much simpler solution.
Just create your own LayoutManager and overwrite the method
getChildCount()
The result should be something like this:
That way, when you add this LayoutManager to the Recyclerview, it will just display 3 items at a time, no matter how many items the adapter has.
And, if you want a Pager like experience when scrolling just add a
SnapHelper