在NestedScrollView中,对于大数据,Recycler View加载速度非常慢

Gur*_*thi 10 java android android-recyclerview android-nestedscrollview

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

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

<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>
Run Code Online (Sandbox Code Playgroud)

배준모*_*배준모 9

这种情况在RecyclerView里面NestedScrollView.

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

如果数据有200个项目,则会冻结onCreateViewHolder()200次.

  • 那么我们怎样才能克服这个问题呢? (3认同)
  • 不要在 NestedScrollView 中使用 RecyclerView (3认同)
  • 或<android.support.v7.widget.RecyclerView android:layout_width ="wrap_content"android:layout_height ="500dp"android:orientation ="vertical"> (2认同)