在NestedScrollView中时,Recycler View加载大型数据的速度非常慢 [英] Recycler View loading very slow for large data when inside NestedScrollView

查看:840
本文介绍了在NestedScrollView中时,Recycler View加载大型数据的速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NestedScrollView中添加了RecyclerView.基本上,我希望RecyclerView与其他视图一起滚动.我面临的问题是,对于一小部分数据,它可以正常工作,但是对于大数据集(200个条目),每当我启动活动时,它冻结大约3-5秒,然后加载.我删除了NestedScrollView,它可以正常工作,但是没有提供我想要的行为.

I have added RecyclerView inside my NestedScrollView. Basically I want RecyclerView to scroll with other Views. The problem that I am facing is that for a small set of data, it is working fine, but for a large set of data(200 entries) whenever I launch the activity, it freezes for about about 3-5 seconds and then loads. I removed the NestedScrollView and it is working flawlessly, but it doesn't provide me the behaviour I want.

(有关其他信息,我正在从SQLite数据库加载数据.滚动没有问题,因为它很平滑.唯一的问题是活动冻结了一段时间)

(For extra info, I am loading the data from SQLite database. There is no problem in scrolling, as it is smooth. The only problem is the activity is freezing for a while)

<android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <... Some other Views ...>

                <android.support.v7.widget.RecyclerView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:orientation="vertical">

                </android.support.v7.widget.RecyclerView>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>

推荐答案

NestedScrollView内的RecyclerView的这种情况.

RecyclerView调用onCreateViewHolder()次等于您的数据大小.

RecyclerView is calling onCreateViewHolder() times equal to your data size.

如果数据有200个项目,它将冻结onCreateViewHolder()被调用200次.

If data has 200 items, it freezes for onCreateViewHolder() to be called 200 times.

这篇关于在NestedScrollView中时,Recycler View加载大型数据的速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆