0

我有兩個RecyclerViews,我想垂直滾動到一起。其中一個也必須能夠水平滾動。我做了什麼來達到這個目的是把它們放在ScrollViews。爲了達到預期效果,我禁用了nestedScrollingEnabled。他們一起滾動非常順利,但我現在有一個不同的問題:RecyclerViews一次加載所有視圖,而不是回收視圖,這會嚴重影響用戶界面。每次我想要顯示RV或更改其中的數據集時,我都會看到超過100幀的跳幀。我該如何更好地處理這個問題?兩個RecyclerViews同步並滾動平滑,但加載非常緩慢

這是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> 

回答

0

我最終擺脫垂直ScrollView的全部,並用scrollBy實現同步滾動。 RecyclerViews現在正確回收,問題解決了!