RecyclerView LinearLayoutManager.scrollToPositionWithOffset dose not work

人走茶凉 提交于 2019-12-06 10:50:33

问题


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?

My code:

init the RecyclerView:

mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

and in the Button onClick, I do this to scroll the View:

((LinearLayoutManager)mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(position, offset);

回答1:


I think you should use mRecyclerView.smoothScrollToPosition(position) where position is your current position + offset.



来源:https://stackoverflow.com/questions/31265476/recyclerview-linearlayoutmanager-scrolltopositionwithoffset-dose-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!