我正在开发一个使用 RecyclerView 幻灯片显示图像的应用程序。我使用下面的代码水平滚动回收器视图。
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(activity, LinearLayout.HORIZONTAL, false);
imageListRecyclerView.setLayoutManager(mLayoutManager);
另外,我使用下面的代码一次滚动一项。
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(imageListRecyclerView);
问题是我想使用获取当前可见项目的位置
holder.getAdapterPosition()
但它不起作用。谁能告诉怎么做吗?
有一些辅助方法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()
欲了解更多信息,请检查这份官方文件 https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#findFirstCompletelyVisibleItemPosition().
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)