5

Ich habe ein Layout erstellt, das zwei RecyclerViews hat. Einer scrollt horizontal, während andere vertikal scrollt. Ich kann in jedem RecyclerView korrekt blättern, aber die Seite als Ganzes scrollt nicht, d. H. Der obere RecyclerView bleibt oben immer und der untere bleibt unten, so wie beide in der Position fixiert sind.Scrolling mit mehreren RecyclerViews im Layout

Es folgt mein xml Layout:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <EditText 
      android:id="@+id/search" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:hint="Search Dramas" 
      android:textSize="16sp" 
      android:paddingLeft="10dp" 
      android:gravity="center" 
      android:textColor="@color/dark_grey" 
      android:textColorHint="@color/dark_grey" 
      android:background="@drawable/border_bottom"/> 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/border_bottom_background_black" 
      android:textColor="@color/white" 
      android:padding="10dp" 
      android:text="Most Watched"/> 

     <!-- A RecyclerView to display horizontal list --> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/featured" 
      android:scrollbars="none" 
      android:layout_width="fill_parent" 
      android:layout_height="240dp" 
      android:paddingLeft="0dp" 
      android:paddingRight="15dp" 
      android:paddingTop="15dp" 
      android:paddingBottom="25dp" 
      android:background="@color/black"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/border_bottom_backgroundless" 
      android:textColor="@color/dark_grey" 
      android:padding="10dp" 
      android:text="All Dramas"/> 

     <!-- A RecyclerView to display vertical list --> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/pick_item" 
      android:scrollbars="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent"/> 


</LinearLayout> 

How activity looks

Antwort

6

Ich war in der Lage, das Problem zu lösen, indem Sie alles in ScrollView setzen und dann Höhe des vertikalen RecyclerView manuell/programmgesteuert einstellen.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/scrollView"> 

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

      <EditText 
       android:id="@+id/search" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:hint="Search Dramas" 
       android:textSize="16sp" 
       android:paddingLeft="10dp" 
       android:gravity="center" 
       android:textColor="@color/dark_grey" 
       android:textColorHint="@color/dark_grey" 
       android:background="@drawable/border_bottom"/> 


      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/border_bottom_background_black" 
       android:textColor="@color/white" 
       android:padding="10dp" 
       android:text="Most Watched"/> 

      <!-- A RecyclerView to display horizontal list --> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/featured" 
       android:scrollbars="none" 
       android:layout_width="fill_parent" 
       android:layout_height="240dp" 
       android:paddingLeft="0dp" 
       android:paddingRight="15dp" 
       android:paddingTop="15dp" 
       android:paddingBottom="25dp" 
       android:background="@color/black"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/border_bottom_backgroundless" 
       android:textColor="@color/dark_grey" 
       android:padding="10dp" 
       android:text="All Dramas"/> 

      <!-- A RecyclerView to display list --> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/pick_item" 
       android:paddingBottom="20dp" 
       android:scrollbars="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:minHeight="840dp"/> 


    </LinearLayout> 
</ScrollView> 

Einstellung RecyclerView Höhe programmatisch:

LinearLayout.LayoutParams params = new  
    LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
    ViewGroup.LayoutParams.WRAP_CONTENT); 
// calculate height of RecyclerView based on child count 
params.height=1150; 
// set height of RecyclerView 
recyclerView.setLayoutParams(params); 
+0

Verlierst du die RecycleVew Optimierung, nicht? Mit anderen Worten, die RecycleView wird die Ansichten nicht recyceln. –

3

RecyclerView nur gewonnen (noch begrenzt) Unterstützung für verschachtelte Scrollen in Version 22.2.0 - mein erster Vorschlag, zu versuchen wäre.

Die einzige Ansicht, die vollständig verschachtelte Scrollen unterstützt ist NestedScrollView (Sie können dies mit der Feststellung sehen kann, dass es sowohl NestedScrollingChild und NestedScrollingParent implementiert) und wurde zur Unterstützung v4 Version 22.1.0 (leicht verbessert in 22.2.0) zugegeben. Wenn Sie nur ein einzelnes horizontales RecyclerView als oberstes Element in Ihrer vertikalen RecyclerView haben, können Sie stattdessen dieses durch ein NestedScrollView ersetzen, das eine LinearLayout mit Ihrer horizontalen RecyclerView gefolgt von Ihrer vertikalen RecyclerView enthält.

+0

ich in einem Layout drei Recycler Ansicht verwendet und in einer Scroll-Ansicht. Meine Recycler-Ansichtsobjekte in der zweiten Recycler-Ansicht werden gescrollt. und ich wollte alle Elemente ohne Scrollen zeigen. aber Erfolg mit NestedScrollView. danke –