I want to scroll to the bottom of a recycler view on click of a button, how do I do this?
You have to make use of LayoutManager
for that. Follow the below steps.
1). First of all, declare LayoutManager
in your Activity/Fragment
. For example, I have taken LinearLayoutManager
private LinearLayoutManager mLinearLayoutManager;
2). Initialise the LinearLayoutManager
and set that to your RecyclerView
mLinearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(mLinearLayoutManager);
3). On your Button onClick
, do this to scroll to the bottom of your RecyclerView
.
mLinearLayoutManager.scrollToPosition(yourList.size() - 1); // yourList is the ArrayList that you are passing to your RecyclerView Adapter.
Hope this will help..!!
You can use scrollToPosition() with the index of the last position.
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