Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView with only one item displayed on screen [duplicate]

I have RecyclerView with items ImageView. I want to make RecyclerView to display only one item at time, dragging to edge like ViewPager, when changing. Anyone knows how to achieve this?

I'm using code from this source:

Android Simple RecyclerView Widget Example

Only one difference is that I don't have TextView, only ImageView.

like image 831
Damian Kozlak Avatar asked May 19 '15 09:05

Damian Kozlak


2 Answers

You can use the PagerSnapHelper class:

RecyclerView recyclerFoodItemsHorizontal = (RecyclerView) findViewById(R.id.recycler_food_items_horizontal);
SnapHelper mSnapHelper = new PagerSnapHelper();
mSnapHelper.attachToRecyclerView(recyclerFoodItemsHorizontal);

It will work similarly to ViewPager.

like image 145
Kshitij Jain Avatar answered Nov 07 '22 11:11

Kshitij Jain


As from I see you need a vertical ViewPager. I'm using castorflex/VerticalViewPager library for achieving that for one of my projects. It works just like a ViewPager, no code changes as I can see It's just a copy paste from the v19 ViewPager available in the support lib, where he changed all the left/right into top/bottom and X into Y.

like image 25
Ahmed Hegazy Avatar answered Nov 07 '22 12:11

Ahmed Hegazy