2017-05-10 11 views
1

私は2つのrecyclerView(1秒未満)を持っています。 ScrollViewをスクロールすることで、スクロールが不要になり、すべてのアイテムが表示されるように、すべての要素の高さに合わせてサイズを変更し、サイズを変更する方法あなたの問題の最も簡単な解決がルートスクロール要素としてNestedScrollViewの代わりScrollViewを使用することですRecycleViewのすべての要素をラップします

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/AppTheme.AppBarOverlay"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:popupTheme="@style/AppTheme.PopupOverlay" /> 

     </android.support.design.widget.AppBarLayout> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@+id/appBarLayout" 
      > 

      <LinearLayout 
       android:id="@+id/content_detail" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 

       android:layout_marginTop="15dp" 
       android:orientation="vertical" 
       android:paddingBottom="@dimen/activity_vertical_margin" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:paddingTop="@dimen/activity_vertical_margin"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <LinearLayout 
         android:layout_width="0px" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:orientation="horizontal"> 

         <ImageView 
          android:id="@+id/ivPoster" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_gravity="center" 
          android:layout_weight="1" 
          app:srcCompat="@mipmap/ic_launcher" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_width="0px" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:gravity="center" 
         android:orientation="vertical"> 

         <TextView 
          android:id="@+id/tvTitle" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:gravity="center" 
          android:text="Title" 
          android:textSize="18sp" 
          android:textStyle="bold" /> 

         <TextView 
          android:id="@+id/tvDate" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="01.01.2001" /> 

         <TextView 
          android:id="@+id/tvRate" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="5.10/10" /> 

         <Button 
          android:id="@+id/btFav" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="Mark as favourite" 
          android:textSize="12sp" /> 
        </LinearLayout> 
       </LinearLayout> 


       <TextView 
        android:id="@+id/tvOverview" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:text="Lorem Ipsum" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:textColor="#000df0" 
        android:text="Trailers:" /> 


       <android.support.v7.widget.RecyclerView 
        android:id="@+id/trailerRecyclerView" 

        android:layout_width="match_parent" 
        android:layout_height="wrap_content" /> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:textColor="#000df0" 
        android:text="Reviews:" /> 
       <android.support.v7.widget.RecyclerView 
        android:id="@+id/reviewRecyclerView" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" /> 


      </LinearLayout> 
     </ScrollView> 

    </RelativeLayout> 
</android.support.design.widget.CoordinatorLayout> 

答えて

2

enter image description here

私のxml: は、今ではということになります。

けど...

あなたは本当にこのすべてを考える場合には、それが本当にあなたのコードのパフォーマンスの面での解決策ではありません。それは望みどおりに見えるが、実際は効率的ではないからだ。

あなたのRecyclerViewが内容を(あなたが望むように)ラップすると、一度にすべてのアイテムが膨らみ、実際にはrecyclingの機能は使用されません。すべてのアイテムをメモリに保持するアイテムを再利用しません。基本的には、RecyclerViewではなく、Viewsのトンを作成するコンポーネントとなり、いくつかのデータに基づいてAdapterを使用します。あなたがそのようなものを実装する必要があります

の方法は、(あなたのケースでは正確には4種類)Views複数の種類を膨張Adapterを作成し、あなたの全体のScrollViewするのではなく、単一RecyclerViewを使用することです。このようにAdaptersを作成する方法を記述しているSOには、ここに複数のスレッドがあります。たとえば、hereです。もう少しあなたを助けるために

は、ここにあなたがあなたのビュータイプを計画する必要があります方法は次のとおりです。

関連する問題