question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to stay at bottom of List?

See original GitHub issue

Hi 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:

  1. Init (first time loading the data) -> I want to scroll to the bottom
  2. User is already at the bottom after 1 finished and I get new data -> I want to scroll to the bottom
  3. 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:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
MTRNordcommented, Jan 25, 2019

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

3reactions
ghostcommented, Jan 25, 2019

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.

controller.getAdapter().registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
    @Override
    public void onItemRangeInserted(int positionStart, int itemCount) {
        if(positionStart == 0) {
            layoutManager.scrollToPosition(0);
       }
    }
});
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found