SwipeRefreshLayout中的RecyclerView不是“wrap_content”

问题描述 投票:4回答:2

我有一个RecyclerView作为SwipeRefreshLayout的唯一孩子,我想要RecyclerView wrap_content。当我将它们都设置为“wrap_content”时,它不起作用。 RecyclerView用较少的物品也match_parent。当我删除SwipeRefreshLayout时,RecyclerViewwrap_content。谁能帮我?我的英语很差,也许你无法理解。有人可以帮帮我吗?非常感谢你。

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

android android-recyclerview swiperefreshlayout android-wrap-content
2个回答
6
投票

最后,我计算出来了。来自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>

-1
投票
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container_v"
    android:layout_width="match_parent"
    android:weightSum="1"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".classes.Splash">
    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".5"
        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>

你可以尝试给线性布局赋予重量。它会起作用

© www.soinside.com 2019 - 2024. All rights reserved.