滚动 RecyclerView 滚动到始终位于顶部的位置
Scroll RecyclerView Scroll to position always on top
我正在使用线性布局管理器和 RecyclerView
以及 LinearLayout Manager
来填充一些项目列表。当我第一次显示 recyclerview
并且我使用:
linearLayoutManager.scrollToPosition(desiredindex);
它滚动到我想要的顶部。
现在是棘手的部分 - 当我滚动到 recyclerview
顶部时(即新项目索引将低于 desiredindex
),我调用:
linearLayoutManager.scrollToPosition(desiredindex);
它仍然工作正常,但是当 recyclerview
滚动到 desiredindex,
之外时,recycler view
滚动使得 desiredindex
项目到达底部而不是在顶部,但我希望磁贴滚动到顶部而不是底部。
像这样使用scrollToPositionWithOffset
:
linearLayoutManager.scrollToPositionWithOffset(desiredindex, 0);
scrolltopositionwithoffset(position, offset) 强制指定的项目可见并带有指定的偏移量。偏移量是距 RecyclerView
.
顶部的距离
我正在使用线性布局管理器和 RecyclerView
以及 LinearLayout Manager
来填充一些项目列表。当我第一次显示 recyclerview
并且我使用:
linearLayoutManager.scrollToPosition(desiredindex);
它滚动到我想要的顶部。
现在是棘手的部分 - 当我滚动到 recyclerview
顶部时(即新项目索引将低于 desiredindex
),我调用:
linearLayoutManager.scrollToPosition(desiredindex);
它仍然工作正常,但是当 recyclerview
滚动到 desiredindex,
之外时,recycler view
滚动使得 desiredindex
项目到达底部而不是在顶部,但我希望磁贴滚动到顶部而不是底部。
像这样使用scrollToPositionWithOffset
:
linearLayoutManager.scrollToPositionWithOffset(desiredindex, 0);
scrolltopositionwithoffset(position, offset) 强制指定的项目可见并带有指定的偏移量。偏移量是距 RecyclerView
.