RecyclerView with only one item displayed on screen [duplicate]

这一生的挚爱 提交于 2019-11-27 06:29:44

问题


This question already has an answer here:

  • RecyclerView horizontal scroll snap in center 7 answers

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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/30321691/recyclerview-with-only-one-item-displayed-on-screen

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