我正在使用线性布局管理器RecyclerView
with a LinearLayout Manager
填充一些项目列表。当我显示recyclerview
第一次,我使用:
linearLayoutManager.scrollToPosition(desiredindex);
它滚动到顶部正是我想要的位置。
现在这是棘手的部分 - 当我滚动到顶部时recyclerview
(即新项目指数将低于desiredindex
),我打电话:
linearLayoutManager.scrollToPosition(desiredindex);
它仍然工作正常,但是当recyclerview
已滚动超出desiredindex,
the recycler view
滚动使得desiredindex
项目位于底部而不是顶部,但我希望磁贴滚动到顶部而不是底部。
Use scrollToPositionWithOffset
像这样:
linearLayoutManager.scrollToPositionWithOffset(desiredindex, 0);
带有偏移量的滚动到位置(位置,偏移量) https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager.html#scrollToPositionWithOffset(int,%20int)强制指示的项目以指示的偏移量可见。偏移量是距顶部的距离RecyclerView
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)