0

enter image description here Я пытаюсь добавить два вида ресайклеров в один макет, который находится в Fragment. Но все, что я вижу, это первый RecyclerView. Можно ли добавить два вида ресайклеров, как на изображении выше (оба должны быть видны одновременно), или есть какое-то ограничение в андроиде, которое можно добавить только один просмотр ресайклеров на один полный экран?Множественный просмотр в одном фрагменте, видимом одновременно

<?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

Покажите свой XML. Это можно сделать с помощью LinearLayout и весов. – yennsarah

+0

добавлено макет – user3477811

ответ

0

Избегайте использования слишком много компоновки контейнеров, как Linera Layout в одном XML-файле, то перерисовки в конечном счете приведет к проблемам памяти. Ваша проблема может быть решена с помощью одного LinearLayout и установив высоту вашей RecyclerViews к 0dp и layout_weight к «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

Я попробую это и вернусь к вам – user3477811

+0

его не работает :( , когда я использовал два вида ресайклеров на одном макете с весами, второй вид ресайклера вообще не загружался. Только пустое место – user3477811

+0

Do у вас есть данные во втором RecyclerView? Вы добавили что-нибудь в свой макет рядом с двумя RecyclerViews? – yennsarah

0

Набор LinearLayout вес

 <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

Используйте андроид : weightSum, чтобы решить вашу проблему:

проверить ниже расположение

<?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> 

Посмотрите http://developer.android.com/guide/topics/ui/layout/linear.html

+0

Решена ли ваша проблема? @ user3477811 –

+0

Нет проблемы не решена, когда я использовал два вида ресайклеров на одном макете с весами, вторая рециркуляция ler view не загружался вообще. только пустое пространство – user3477811

Смежные вопросы