简体   繁体   中英

Scrolling to bottom of recycler view

I have a recycler view that loads more content when users scroll to the bottom.

To scroll to the bottom once, I can use something like: recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1)

Is it possible to continually scroll the recycler view until it reaches the very end? The recycler view does not have thousands of items so it'll only have to scroll a few times before it reaches the end.

You can easily do this by the following logic:

  1. Scroll your Recycler view to bottom once as per your needs.
  2. As per your response from the server maintain a value which tells if there is more data available for the user. Value can be like 0 or 1.

    0: No more data is available for the user.
    1: More data is available for the user.

  3. If more data is available for the user then after the data is set on the screen again scroll user to bottom of the Recycler View else don't scroll.

Tip: Maintain a delay of about 200-300ms or 500ms(fail safe) after your data is set on the screen and before scrolling to bottom to avoid any errors or crashes.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM