首页 > 解决方案 > 非常大的数据使我的应用程序在使用 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

标签: androidscrollviewandroid-nestedscrollview

解决方案


分页是专门为此构建的。您可以拥有一个为您提供数据的存储库。

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


推荐阅读