如何在回收站视图中一对一滚动?

时间:2021-03-20 14:47:40

标签: java android android-recyclerview

这是我的适配器

我想每次滚动时滚动一项。就像你在 Instagram 上看到多张图片一样。我该怎么做?

谢谢

_vimrc

和我的 XML;

recyclerViewyeterr=findViewById(R.id.recyclerViewyeterr);

LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(GYUserSahaDetay.this, 
LinearLayoutManager.HORIZONTAL, false);

recyclerViewyeterr.setLayoutManager(horizontalLayoutManagaer);

gYresimadaptor=new GYresimadaptor(resimler2);

recyclerViewyeterr.setAdapter(gYresimadaptor);

2 个答案:

答案 0 :(得分:1)

您可以通过使用 SnapHalper.attachToRecyclerView()SnapHelper 附加到您的 RecyclerView 来使用它,并且您将获得类似于 Instagram 的滚动效果,例如:

recyclerViewyeterr=findViewById(R.id.recyclerViewyeterr);

LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(GYUserSahaDetay.this, 
LinearLayoutManager.HORIZONTAL, false);

recyclerViewyeterr.setLayoutManager(horizontalLayoutManagaer);

gYresimadaptor=new GYresimadaptor(resimler2);

recyclerViewyeterr.setAdapter(gYresimadaptor);

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

答案 1 :(得分:1)

据了解,你想制作这个 对于像 instagram 这样超过 1 张照片帖子或历史记录的房车,您必须使用此布局管理器代码,并且必须设计全宽卡片视图。

这是通用的解决方案

rv.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.HORIZONTAL));