Rgfvfk Iff
Rgfvfk Iff

Reputation: 1609

Android Recycler view scroll to bottom

I am trying to scroll the recycler view to the bottom but the problem is if my row item height is greater that the screen height the scrolling stops at the top of the item. Is it possible to manually scroll to the very bottom of a recycler view?

recyclerView.scrollToPosition(adapter.getItemCount()-1); // does not work

Upvotes: 4

Views: 6147

Answers (2)

Sachin Rajput
Sachin Rajput

Reputation: 4344

it will work for you. Use setReverseLayout=true in your LayoutManager and set this to your recylcerView.

final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setReverseLayout(true);

    recyclerView.setLayoutManager(linearLayoutManager);

Upvotes: 1

user4571931
user4571931

Reputation:

In java actually lists are zero based. E.g. list [0,1,2] has a size of 3 but the last position is 2 because it starts with 0.

recyclerView.scrollToPosition(items.size() - 1);

Upvotes: 2

Related Questions