2017-06-15 3 views
0

私は単一のアクティビティで異なるレイアウトの2つのRecyclerViewを実装したいと思います。上記のRecyclerViewは垂直方向にスクロールする必要があり、下側は水平方向にスクロールする必要があります。しかし、私はアプリを実行すると、いずれかのRecyclerViewが表示されます。最初のビューが表示されている場合は正しく動作し、垂直方向にスクロールし、2番目のRecyclerViewは表示されません。そして、2番目のものが表示されている場合は、水平スクロールを行うべきときに垂直方向にスクロールし、最初のRecyclerViewは欠落します。シングルアクティビティで2つのrecyclerViewを使用するには?

Here is what i want.出典:Githubには、CardView-Recyclerview-ピカソ

は、ここに私のレイアウト

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/colorBackgroundLight" 
    android:smoothScrollbar="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/CategoriesRecyclerView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/videoRecyclerView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="130dp" 
      android:layout_below="@+id/CategoriesRecyclerView"/> 

    </RelativeLayout> 

</android.support.v4.widget.NestedScrollView> 
+0

動作していないと、両方のRecyclerviewsにデータが表示されます。彼らは空です。 – Ganesh

答えて

0

あなたが直接NestedScrollViewなし2つのリサイクラービューを使用することです。

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/videoRecyclerView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="130dp" 
      android:layout_below="@+id/CategoriesRecyclerView"/> 

    </RelativeLayout> 

と高さであるwrap_content、recylerビューで使用するレイアウトマネージャにsetAutoMeasureEnabled(true)を使用し、あなたのCategoriesRecyclerViewで

+0

私はCollapsingToolbarLayoutを持っています。 – Ganesh

0

ページスクロールで水平スクロールビューを上下にスクロールしたい場合は、スクロールビューを使用します。スクロールビューを使用しない場合は、スクロールビューを使用しないでください。また、あなたのレイアウトを達成するためには、水平のrecyclerview固定高さを与えて、あなたは両方のrecyclerviewを見ることができます。

+0

私はCollapsingToolbarLayoutを持っています。そして私は固定された高さを追加しようとしましたが、何も動作しません。どちらのレイアウトも同じリサイクルビューを使用していると思います。デバッグでは、2番目のrecyclerviewがnullを示しています。 – Ganesh

関連する問題