我正在编写一个可滚动整个页面的android应用程序。因此,我尝试使用NestedScrollView,但由于数据非常大(例如,超过1000条记录,最多可以有10000条记录),因此创建回收视图的视图太慢,然后使应用程序崩溃。
所以我正在使用下面的代码来解决上述问题。
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (!recyclerView.canScrollVertically(1))
onScrolledToBottom();
}
});
可以帮助减少时间,但问题是屏幕无法滚动显示整个页面。
如何处理此问题?
ID:
item1
item2
item3
item4
item5
item6
...
item1000
分页是专门为此构建的。您可以有一个可以为您提供数据的存储库。
class YourRepository{
/**
* Offset would indicate the starting index of data that you need
* Count indicates the amount of data you need
**/
List<Data> getData(int count, int offset){}
}
有了这个API,您可以相当有效地使用Jetpack Paging库。https://developer.android.com/topic/libraries/architecture/paging