How to stay at bottom of List?
See original GitHub issueHi I want to use this as a Whatsapp Like Message List. How can I get the list to stay at the bottom if the user is at the bottom when doing submitList on a PagedListEpoxyController?
Means I have 3 states:
- Init (first time loading the data) -> I want to scroll to the bottom
- User is already at the bottom after 1 finished and I get new data -> I want to scroll to the bottom
- User is somewhere in the list aka not bottom after 1 finished and I get new data -> I dont want to scroll to the bottom
How can I archive that? I currently try to do it via the following code but is there a better way of doing it?
val recyclerLayoutManager: LinearLayoutManager = recyclerView.layoutManager as LinearLayoutManager
viewModel.messageList(intent.getStringExtra("roomID")).observe(this@ChatRoom, Observer {
// Submit Data
pagingController.submitList(it)
// Check if we are at the bottom and scroll
if (recyclerLayoutManager.findLastCompletelyVisibleItemPosition() == recyclerView.childCount) {
recyclerView.smoothScrollToPosition(recyclerView.childCount)
}
})
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to make this list stay at the bottom of the page?
This should do it. Fix the footer using position: fixed; and set bottom: 0px; to fix it to the bottom of the page....
Read more >How to keep your footer where it belongs ? - freeCodeCamp
For a quick fix, you can absolutely position the footer at the bottom of the page. But this comes with its own downside....
Read more >How to position a div at the bottom of its container using CSS?
Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to...
Read more >margin-bottom - CSS: Cascading Style Sheets - MDN Web Docs
The margin-bottom CSS property sets the margin area on the bottom of an element. A positive value places it farther from its neighbors, ......
Read more >CSS bottom Property - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got it. This awnser on stackoverflow gave me the last needed hint: https://stackoverflow.com/a/53316955/4929236
Basicly set the LLM to reverselayout and setStackFromEnd to false. And order the db query in DESC mode
You shouldn’t be scrolling to the bottom of the list - instead there is a great property on LinearLayoutManager to reverse the layout to be bottom to top. That should solve issues #1 and #3. See: https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager#setreverselayout
As for not scrolling if the user is at a certain position when data is added, you can use the solution explained at https://github.com/airbnb/epoxy/issues/224 and add an adapter data observer. You may actually not need this if you’ve done the above with reverse layout on LLM, but if that doesn’t do the trick, try the below.