Jserra
Jserra

Reputation: 169

RecyclerView Scroll one element at a time

I have a Recyclerview containing images, each image filling the view completely. I want the user to be able to scroll them one at a time, so it does not scroll more than one element, and it stops at the beginning of each element.

I tried adding a scroll listener, but I am unable to lock the scrolling.

Do you know how to achieve this behavior?

Upvotes: 3

Views: 3593

Answers (2)

Mattia Ferigutti
Mattia Ferigutti

Reputation: 3708

As you can see here the best solution I've could find is:

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
SnapHelper snapHelper = new PagerSnapHelper();
recyclerView.setLayoutManager(layoutManager);
snapHelper.attachToRecyclerView(mRecyclerView);

Setting the orientation vertical it should work

Upvotes: 3

se_bastiaan
se_bastiaan

Reputation: 1704

Don't use a RecyclerView. Use a ViewPager that has a vertical direction. http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Upvotes: 1

Related Questions