如何在RecyclerView中找到当前可见项目的位置?

编程入门 行业动态 更新时间:2024-10-10 19:25:06
本文介绍了如何在RecyclerView中找到当前可见项目的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个使用RecyclerView幻灯片显示图像的应用程序.我使用下面的代码水平滚动了回收站视图.

I am working on an app which slideshows the images using RecyclerView. I used the below code to horizontally scroll the recycler view.

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(activity, LinearLayout.HORIZONTAL, false); imageListRecyclerView.setLayoutManager(mLayoutManager);

此外,我正在使用以下代码一次滚动一个项目.

Also, I am using the below code to scroll one item at a time.

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

问题是我想使用获取当前可见项的位置

The problem is that I want to get the position of current visible item using

holder.getAdapterPosition()

,但是它不起作用.谁能告诉我怎么做?

but it is not working. Can anyone tell how to do it?

推荐答案

LinearLayoutManager的一些帮助方法

findFirstCompletelyVisibleItemPosition() Returns the adapter position of the first fully visible view. int findFirstVisibleItemPosition() Returns the adapter position of the first visible view. int findLastCompletelyVisibleItemPosition() Returns the adapter position of the last fully visible view. findLastVisibleItemPosition()

有关更多信息,请参见此正式文档.

for more information check this official document.

更多推荐

如何在RecyclerView中找到当前可见项目的位置?

本文发布于:2023-11-08 20:48:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570416.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   项目   中找到   如何在   RecyclerView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!