如何制作SwipeRefreshLayout wrap_content? [英] How to make SwipeRefreshLayout wrap_content?

查看:91
本文介绍了如何制作SwipeRefreshLayout wrap_content?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作SwipeRefreshLayout wrap_content?

How to make SwipeRefreshLayout wrap_content?

这是我的布局 mydialog_fragmet.xml :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/appBackgroundColorLight"
        android:orientation="vertical"
        >

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingTop="16dp"
            android:scrollbarSize="2dp"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbarThumbVertical="@color/colorAccent"
            />

        <include layout="@layout/view_add_place_button"/>

    </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>

结果是LinearLayout id/contentLayout 变为 match_parent .这是屏幕截图:

In result LinearLayout id/contentLayout becomes match_parent. Here is screenshot :

但是当我使用没有 SwipeRefreshLayout 的布局时,内容是 wrap_content : mydialog_fragmet.xml :

But when I use the layout without SwipeRefreshLayout content is wrap_content: mydialog_fragmet.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/appBlue"
            android:orientation="vertical"
            >

            <android.support.v7.widget.RecyclerView
                android:id="@+id/placesRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:paddingTop="16dp"
                android:scrollbarSize="2dp"
                android:scrollbarStyle="outsideOverlay"
                android:scrollbarThumbVertical="@color/colorAccent"
                app:maxHeight="300dp"
                />

            <include layout="@layout/view_add_place_button"/>

        </LinearLayout>

这是正确的结果:

推荐答案

此特定行为的解决方案是将视图包装在父级布局中,仅当您希望使用该大小的dp时才建议使用特定的dp

The solution for this specific behavior is to wrap the view in a parent layout, using a specific dp is only recommended if you want it on that size

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/appBackgroundColorLight"
        android:orientation="vertical">

   <android.support.v4.widget.SwipeRefreshLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/appBackgroundColorLight"
        android:orientation="vertical"
        >

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingTop="16dp"
            android:scrollbarSize="2dp"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbarThumbVertical="@color/colorAccent"
            />

        <include layout="@layout/view_add_place_button"/>

    </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>

这篇关于如何制作SwipeRefreshLayout wrap_content?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆