水平回收视图捕捉到中心,同时显示上一个/下一个项目

问题描述 投票:1回答:1

我想实现这一目标。 first item of recyclerview with next item visible second item of recyclerview with previous and next item visible

我设法通过将适配器的宽度设置为静态值并在recyclelerview的开始和结束时添加填充来实现它,但是,由于适配器的宽度是静态的,因此它不能在较小/较大的屏幕设备上缩放。有关如何在支持不同屏幕尺寸的同时实现此功能的任何想法?或者我可以用来实现这个目标的任何库?谢谢

android android-layout android-recyclerview
1个回答
2
投票

您可以通过将snaphelper添加到recycler视图来使项目居中

//to center item of recyclerview when scrolling it.
        SnapHelper snapHelper = new LinearSnapHelper();
        snapHelper.attachToRecyclerView(yourRecyclerview);
© www.soinside.com 2019 - 2024. All rights reserved.