非常大的数据使我的应用程序在使用ScrollView时非常慢

问题描述 投票:0回答:1

我正在编写一个可滚动整个页面的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

android scrollview android-nestedscrollview
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.