Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView in SwipeRefreshLayout not "wrap_content"

I have a RecyclerView as the only child of SwipeRefreshLayout, I want the RecyclerView wrap_content. When I set both of them "wrap_content", it doesn't work. The RecyclerView with fewer items also match_parent. When i delete SwipeRefreshLayout, the RecyclerView will wrap_content. Can anyone help me? My English is poor, Maybe you cann't understand. Anyone can help me? Thank you very much.

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00ffff">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ff00ff">

    </android.support.v7.widget.RecyclerView>

</android.support.v4.widget.SwipeRefreshLayout>
like image 372
秃德666 Avatar asked Dec 03 '16 06:12

秃德666


1 Answers

Finally, I work out it. From this Answer

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00ffff">

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ff00ff"/>

        </LinearLayout>
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
like image 52
秃德666 Avatar answered Nov 15 '22 18:11

秃德666