5

我在NestedScrollView裏面加了RecyclerView。基本上我想要RecyclerView與其他視圖滾動。我面臨的問題是,對於一小部分數據,它工作正常,但對於大量數據(200條),只要我啓動活動,就會凍結大約3-5秒,然後加載。我刪除了NestedScrollView,它的工作完美無瑕,但它並沒有爲我提供我想要的行爲。Recycler查看加載非常緩慢的大數據時內部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> 
+0

嘗試'recyclerView.setNestedScrollingEnabled(false);' –

+0

是的我已經試過了,它不工作,正如我所說的,滾動沒有問題 –

+0

請顯示您的java代碼,從數據庫中提取數據的位置您正在將這些數據填充到您的佈局中。 –

回答

5

NestedScrollViewRecyclerView的情況。

RecyclerView正在調用onCreateViewHolder()次數等於您的數據大小。

如果數據有200個項目,則凍結爲onCreateViewHolder()被稱爲200次。

+1

因爲根視圖NestedScrollView,recyclerview高度是無窮大 –

+0

那麼我們該如何克服這個問題呢? –

+0

?找到另一種方式。使用https://github.com/martijnvdwoude/recycler-view-merge-adapter –

-2

正如Nancy所說,recyclerview.setNestedScrollingEnabled(false);將解決滾動卡住的問題。我也面臨這種類型的問題,並通過錯誤的NestedScroll解決。

+2

滾動不是問題,問題在於活動凍結了幾秒鐘,當它完全加載時它完美地滾動,我始終使用setNestedScrollingEnabled(false)選項,但沒有勝利! –

+0

@GurleenSethi你有沒有找到任何解決方案呢?我現在面臨同樣的問題。 – viper