【问题标题】:Two RecyclerViews are in sync and scroll smoothly, but load very slowly两个 RecyclerView 同步并平滑滚动,但加载速度很慢
【发布时间】:2017-02-03 16:05:18
【问题描述】:

我有两个 RecyclerViews 我想一起垂直滚动。其中之一还必须能够水平滚动。我所做的就是将它们放在ScrollViews 中。为了获得预期的效果,我禁用了nestedScrollingEnabled。它们一起滚动非常顺利,但我现在有一个不同的问题:RecyclerViews 一次加载所有视图,而不是回收视图,这对 UI 造成了严重影响。每次我想显示我的 RV 或更改其中的数据集时,都会看到超过 100 帧的帧跳过。我怎样才能更好地解决这个问题?

这是 XML。请不要介意宽度和高度值,因为它们是通过编程设置的。

<ScrollView
    android:id="@+id/verticalScrollView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/headerConstraintLayout"
    app:layout_constraintVertical_bias="1.0">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            layout="@layout/first_recyclerview"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent" />

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView"
            android:layout_width="40dp"
            android:layout_height="0dp"
            android:layout_marginLeft="100dp"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent">

            <include
                layout="@layout/second_recyclerview"
                android:layout_width="100dp"
                android:layout_height="wrap_content" />
        </HorizontalScrollView>

    </android.support.constraint.ConstraintLayout>
</ScrollView>

【问题讨论】:

    标签: android android-recyclerview scrollview android-scrollview


    【解决方案1】:

    我最终完全摆脱了垂直的ScrollView,并使用scrollBy 来实现同步滚动。 RecyclerViews 现在可以正常回收了,问题解决了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 2015-05-15
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      相关资源
      最近更新 更多