2017-08-13 97 views
1

我用两个RecyclerView一个NestedScrollView内。该设置很好,但我担心它可能具有的内存影响。我不确定RecylerView是否会像它那样回收组件。这有什么其他缺点吗?RecyclerView会回收NestedScrollView内的项目吗?

下面是一些代码:

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/nested_coordinator_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="54dp" 
    android:background="@color/white" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <RelativeLayout 
     android:id="@+id/toplayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycleview1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:nestedScrollingEnabled="false"/> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycleview2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/recycleview1" 
      android:nestedScrollingEnabled="false"/> 

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

回答

2

RecyclerView不回收的物品时,它是一个NestedScrollView内。事实上,当你setNestedScrollingEnabled(false)的观点,将完全展开和滚动行为应该由它的父,这是在你的情况下,NestedScrollView提供。所以,如果你有一个无限的RecyclerView,那么当项目数量增加时,内存和性能将会降低。但是,只要你的项目的数量没有那么多,这会影响内存和性能,采用RecyclerViewNestedScrollView是不坏的错误。但很明显,最好不要这样做。

相关问题