How to scroll to the bottom of a RecyclerView? scrollToPosition doesn't work
Just set setStackFromEnd=true
or setReverseLayout=true
so that LLM will layout items from end.
The difference between these two is that setStackFromEnd
will set the view to show the last element, the layout direction will remain the same. (So, in an left-to-right horizontal Recycler View, the last element will be shown and scrolling to the left will show the earlier elements)
Whereas setReverseLayout
will change the order of the elements added by the Adapter. The layout will start from the last element, which will be the left-most in an LTR Recycler View and then, scrolling to the right will show the earlier elements.
Sample:
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setReverseLayout(true);
_listView.setLayoutManager(linearLayoutManager);
See documentation for details.
Scroll to the bottom of the Recycler View problem
I had a mistake that I put the recycler view inside a scroll view, so the code I used above didn't work like expected, just remove the scroll view and everything is normal again.
Automatically scroll to bottom of RecyclerView
Please use smoothScrollToPosition
to fix your issue.
I always use smoothScrollToPosition
for redirecting to any position.
Make sure, mMessages
size is good as you thinking.
Example,
RecyclerView rv = (RecyclerView)findViewById(R.id.recyclerView);
rv.smoothScrollToPosition(mMessages.count-1);
RecyclerView - Scroll To Position Not Working Every Time
I had the same issue some weeks ago, and found only a really bad solution to solve it. Had to use a postDelayed
with 200-300ms.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
yourList.scrollToPosition(position);
}
}, 200);
If you found a better solution, please let me know! Good luck!
RecyclerView scrolling to the bottom
You can scroll to last position of recycler view by adding this line
recyclerView.scrollToPosition(YourArraylist.size()-1);
add this after setting adapter
Related Topics
How to Replace Dot (.) in a String in Java
Eclipse No Tests Found Using Junit 5 Caused by Noclassdeffounderror for Launcherfactory
Kafka: How to Delete Records from a Topic Using Java API
Java.Time.Format.Datetimeparseexception: Text Could Not Be Parsed At Index 3
Java.Lang.Noclassdeffounderror: Com/Fasterxml/Jackson/Databind/Exc/Invaliddefinitionexception
Notifydatasetchanged() Makes the List Refresh and Scroll Jumps Back to the Top
@Valid Annotation Is Not Working as Expected
Update Elements in a Jsonobject
Check If Url Is Https or Http Protocol
Iterate Through Each Digit in a Number
Java Simpledateformatter With 10 Decimals After the Seconds, Cannot Convert to Date
Java.Io.Filenotfoundexception: the System Cannot Find the File Specified
Spring - Read Property Value from Properties File in Static Field of Class
Refactor Multiple If' Statements in Java-8
How to Use a Regex to Search Backwards Effectively
Spring JPA - Why Is My Findall Returning Null When There Is Data in My Database