naiyu naiyu - 4 months ago 90
Android Question

RecyclerView LinearLayoutManager.scrollToPositionWithOffset dose not work

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);

Answer

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