本文介绍了RecyclerView LinearLayoutManager.scrollToPositionWithOffset无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想滚动RecyclerView
到一个位置,并且我使用LinearLayoutManager.scrollToPositionWithOffset()
滚动,但是它不起作用.有人可以帮我吗?
I want to scroll the RecyclerView
to a position, and I use LinearLayoutManager.scrollToPositionWithOffset()
to scroll, but it does not work. Could any one help me?
我的代码:
初始化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是当前位置+偏移量.
I think you should use mRecyclerView.smoothScrollToPosition(position)
where position is your current position + offset.
这篇关于RecyclerView LinearLayoutManager.scrollToPositionWithOffset无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!