本文介绍了如何在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中找到当前可见项目的位置?
发布评论