mt0s mt0s - 2 months ago 11
Android Question

RecyclerViews in ScrollView not displaying data

I have two recyclerViews inside a

LinearLayout
and the
LinearLayout
inside a
ScrollView
so I can scroll them together. I have tested this in a demo project and works as expected.

Now I move to another project I'm currently working on and I have two recyclerViews the first one displays some data stored in internal storage and the second one displays data I fetch from a network call.

The code for the UI is :

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">

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

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

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

</LinearLayout>
</ScrollView>


But what happens is that I see only the first list. I have tried removing the
ScrollView
from the XML and I can see the data, so it has nothing to do with not getting the data to display.

Should I change something on the code above? I have tried tinkering values of layout_height for both
LinearLayout
and
ScrollView
but it did not help.

dex dex
Answer

Try this

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

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

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

</LinearLayout>

Comments