我想将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);
最佳答案
我认为你应该使用RecyclerView.smoothScrollToPosition(position)
,其中position是你当前的位置+偏移量。
关于android - RecyclerView LinearLayoutManager.scrollToPositionWithOffset 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265476/