简体   繁体   English

滚动到回收站视图的底部

[英]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) 要滚动到底部一次,我可以使用类似以下内容的代码: 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或1。

    0: No more data is available for the user. 0:没有更多数据可供用户使用。
    1: More data is available for the user. 1:更多数据可供用户使用。

  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. 提示:在将数据设置在屏幕上之后以及滚动到底部之前,请保持大约200-300ms或500ms(故障保护)的延迟,以避免任何错误或崩溃。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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