android - 水平回收 View 对齐中心,同时上一个/下一个项目可见

标签 android android-layout android-recyclerview

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

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

最佳答案

您可以通过将 snaphelper 添加到回收站 View 来使项目居中

//to center item of recyclerview when scrolling it.
        SnapHelper snapHelper = new LinearSnapHelper();
        snapHelper.attachToRecyclerView(yourRecyclerview);

关于android - 水平回收 View 对齐中心,同时上一个/下一个项目可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49043324/

相关文章:

android - 停止在 recyclerview 中滚动

安卓 : Facebook like newsfeed with multiple images and videos

android - RecyclerView 的 holder.getAdapterPosition() 返回 -1。导致 ArrayIndexOutOfBoundsException

Java在循环子句上获取类字段并检查值

java - 将值从 Activity 传递到 Android Fragment

android - FrameLayout 中的 ImageButton 和 Button 不会更改 z-index

java - 如何在 Android 中通过名称获取图像资源?

android - 编译 native_app_glue.c 导致库文件无效

android - 使用 RxJava 和播放服务视觉时的致命信号 11 (SIGSEGV)

android - Android 中 Activity 与其布局的关系