RecyclerView LinearLayoutManager.scrollToPositionWithOffset 不起作用
RecyclerView LinearLayoutManager.scrollToPositionWithOffset dose not work
我想将RecyclerView
滚动到某个位置,我使用LinearLayoutManager.scrollToPositionWithOffset()
滚动,但是它不起作用。谁能帮帮我?
我的代码:
初始化 RecyclerView
:
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
在 Button
onClick
中,我这样做是为了滚动 View
:
((LinearLayoutManager)mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(position, offset);
我认为你应该使用 mRecyclerView.smoothScrollToPosition(position)
,其中 position 是你当前的位置 + 偏移量。
我想将RecyclerView
滚动到某个位置,我使用LinearLayoutManager.scrollToPositionWithOffset()
滚动,但是它不起作用。谁能帮帮我?
我的代码:
初始化 RecyclerView
:
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
在 Button
onClick
中,我这样做是为了滚动 View
:
((LinearLayoutManager)mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(position, offset);
我认为你应该使用 mRecyclerView.smoothScrollToPosition(position)
,其中 position 是你当前的位置 + 偏移量。