0

enter image description here Ich versuche, zwei Recycler-Ansichten zu einem einzigen Layout hinzufügen, die in einem Fragment ist. Aber alles, was ich sehen kann, ist die erste RecyclerView. Ist es möglich, zwei Recycler-Ansichten wie im obigen Bild hinzuzufügen (beide müssen gleichzeitig sichtbar sein), oder gibt es eine Einschränkung in Android, dass nur eine Recycler-Ansicht zu einem vollständigen Bildschirm hinzugefügt werden kann?Mehrere Recycler-Ansicht in einem Fragment sichtbar gleichzeitig

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

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent"> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/test_recycle1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="#FFCC00" 
     android:dividerHeight="4px" 
     android:background="#e0e0e0"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/test_recycle2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="#FFCC00" 
     android:dividerHeight="4px" 
     android:background="#e0e0e0"/> 
     </LinearLayout> 

</LinearLayout> 
+0

Zeigen Sie Ihre xml. Dies kann mit einem LinearLayout und Gewichten erfolgen. – yennsarah

+0

hinzugefügt das Layout – user3477811

Antwort

0

Vermeiden Sie zu viele Layout-Container wie Linera Layout in einer XML-Datei, die Überziehung führt schließlich zu Speicherproblemen. Ihr Problem kann durch die Verwendung einer LinearLayout und durch Einstellen der Höhe Ihres RecyclerViews-0dp und die layout_weight gelöst werden auf "1":

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

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/test_recycle1" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:divider="#FFCC00" 
     android:dividerHeight="4px" 
     android:background="#e0e0e0"/> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/test_recycle2" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:divider="#FFCC00" 
     android:dividerHeight="4px" 
     android:background="#e0e0e0"/> 
</LinearLayout> 
+0

Ich werde das versuchen und zurück zu Ihnen – user3477811

+0

es funktioniert nicht :( wenn ich zwei Recycler Ansichten auf einem Layout mit Gewichten verwendet, die zweite Recycler Ansicht nicht geladen wurde. Nur eine leere Stelle – user3477811

+0

Do Sie haben irgendwelche Daten in Ihrem zweiten RecyclerView? Haben Sie etwas zu Ihrem Layout neben den beiden RecyclerViews hinzugefügt? – yennsarah

0

Set Linearlayout Gewicht

 <android.support.v7.widget.RecyclerView 
      android:id="@+id/test_recycle1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:divider="#FFCC00" 
      android:dividerHeight="4px" 
      android:layout_weight="1" 
      android:background="#e0e0e0"/><!----> 



     <android.support.v7.widget.RecyclerView 
      android:id="@+id/test_recycle2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:divider="#FFCC00" 
      android:layout_marginTop="20dp" 
      android:dividerHeight="4px" 
      android:layout_weight="1" 
      android:background="#e0e0e0"/> 


</LinearLayout> 
0

Verwenden android : weightSum, um dein Problem zu lösen:

check unten Layout

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/test_recycle1" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:background="#e0e0e0" 
      android:divider="#FFCC00" 
      android:dividerHeight="4px" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/test_recycle2" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:background="#e0e0e0" 
      android:divider="#FFCC00" 
      android:dividerHeight="4px" /> 
    </LinearLayout> 

</LinearLayout> 

Werfen Sie einen Blick auf http://developer.android.com/guide/topics/ui/layout/linear.html

+0

Ist Ihr Problem gelöst? @ user3477811 –

+0

Nein das Problem ist nicht gelöst, wenn ich zwei Recycler Ansichten auf einem Layout mit Gewichten verwendet, die zweite Rezyklierung Die Ansicht hat überhaupt nicht geladen. nur ein Leerzeichen – user3477811

Verwandte Themen