0

I'm wrapping 2 headers and 2 RecycleView with ScrollView so that my screen can scroll if the item overflow. Each RecycleView can only contain 3 item.

This is what I'm trying to achieve enter image description here

But what I get is the second RecycleView at the bottom, can only show one item. And I don't know why.

This is my XML layout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
tools:context="com.udaily.udaily.view.fragment.NewsFragment">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:weightSum="100">

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="40"
                    android:adjustViewBounds="false"
                    android:scaleType="fitCenter"
                    android:src="@drawable/infonitas" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="30"
                    android:gravity="center_vertical">

                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:layout_marginLeft="5dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="30"
                    android:gravity="center_vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:gravity="center_vertical"
                        android:text="Lihat Semua >>>"
                        android:textSize="12dp" />
                </LinearLayout>


            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/newsInfonitas"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="20dp"
                android:paddingRight="20dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:orientation="horizontal"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:weightSum="100">

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="40"
                    android:adjustViewBounds="false"
                    android:scaleType="fitCenter"
                    android:src="@drawable/indochinatown" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="30"
                    android:gravity="center_vertical">

                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:layout_marginLeft="5dp"
                        android:layout_marginRight="5dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="30"
                    android:gravity="center_vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="30dp"
                        android:gravity="center_vertical"
                        android:text="Lihat Semua >>>"
                        android:textSize="12dp" />
                </LinearLayout>


            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/newsIndoChina"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="20dp"
                android:paddingRight="20dp" />


        </LinearLayout>
    </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>

Can someone guide how to show full content at the second RecycleView

k_ssb
  • 6,024
  • 23
  • 47
BIlly Sutomo
  • 407
  • 1
  • 6
  • 20
  • Possible duplicate of [How to add a recyclerView inside another recyclerView](https://stackoverflow.com/questions/34569217/how-to-add-a-recyclerview-inside-another-recyclerview) – Reaz Murshed May 12 '18 at 05:33
  • I think you need to get rid of that `ScrollView` and try to put both of your list in the same `RecyclerView`. – Reaz Murshed May 12 '18 at 05:33

2 Answers2

2

Replace height with android:layout_height="0dp" and put android:layout_weight="1" to both recyclerview.

Just like below code:

 <android.support.v7.widget.RecyclerView                  
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"/>
Jaymin
  • 2,879
  • 3
  • 19
  • 35
0

Replace height with android:layout_height="0dp" and put android:layout_weight="1" to both recyclerviews and adjust using weights to Linear Layout.

<android.support.v7.widget.RecyclerView                  
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"/>