android - 非常大的数据使我的应用程序在使用 ScrollView 时非常慢
问题描述
我正在编写一个整个页面可滚动的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:<输入框>
项目1
项目2
第 3 项
第 4 项
项目5
第 6 项
...
项目1000
解决方案
分页是专门为此构建的。您可以拥有一个为您提供数据的存储库。
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
推荐阅读
- r - R在切片向量时附加'NA'
- ios - 更新 Xcode 11.1 的约束问题
- python - 将 curl 请求转换为 python 请求
- laravel - 如何从多个关系中获取数据
- javascript - 验证月/年是否大于当前日期
- flutter - 在 Flutter 中将 Widget 从单独文件添加到主文件
- javascript - 在 JavaScript 中,属性名称周围的花括号是什么?
- osisoft - 如何在 PI-Web API 中通过属性名称和属性值查找元素
- laravel - Laravel - 如何在不活动 30 分钟后自动注销并重定向到登录页面
- python - 如何在情节中为ticktext着色?