I am trying to programmatically scroll to a position in my RecyclerView
, this is what I've tried until now nothing worked in my case:
musicList.getLayoutManager().smoothScrollToPosition(musicList, null, position);
musicList.scrollToPosition(position);
mLayoutManager.scrollToPosition(position);
musicList.getLayoutManager().scrollToPosition(position);
Is there something I missed?
I have a LinearLayoutManager mLayoutManager;
defined and set it to RecyclerView
as this:
mLayoutManager = new LinearLayoutManager(this);
musicList.setLayoutManager(mLayoutManager);
RecyclerView XML:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/musicList"
android:scrollbars="vertical"
android:scrollbarThumbVertical="@drawable/custom_scrollbar_vertical"/>
Did you try with LinearLayoutManager method scrollToPositionWithOffset
//position 2 and second param is offset 20
mLayoutManager.scrollToPositionWithOffset(2, 20);
this works for me. Hope to work and for you !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With