How to make swipe on horizontal recyclerview bring only the next item into view - Android

喜你入骨 提交于 2019-12-11 00:16:08

问题


I have a horizontal RecyclerView that shows 4 cards numbered 1-4. These cards take up the entire width of the screen so only 1 card can be fully visible at a time. The user is presented with the first card, when they swipe the card to the left like this,

the RecyclerView will scroll all the way to number 4. I don't want that.

I want the swipe to bring the next card (number 2) into the view

Similar to how Androids ViewPager works.


回答1:


SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);

Added in android.support library



来源:https://stackoverflow.com/questions/38778461/how-to-make-swipe-on-horizontal-recyclerview-bring-only-the-next-item-into-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!