[英]How to make SwipeRefreshLayout wrap_content?
How to make SwipeRefreshLayout wrap_content?如何使 SwipeRefreshLayout wrap_content?
Here is my layout mydialog_fragmet.xml :这是我的布局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>
In result LinearLayout id/contentLayout
becomes match_parent
.结果 LinearLayout
id/contentLayout
变成match_parent
。 Here is screenshot :这是屏幕截图:
But when I use the layout without SwipeRefreshLayout
content is wrap_content
: mydialog_fragmet.xml :但是当我使用没有
SwipeRefreshLayout
的布局时,内容是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>
Here is right result:这是正确的结果:
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此特定行为的解决方案是将视图包装在父布局中,仅当您希望使用特定大小时才建议使用特定 dp
<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>
Found solution:找到解决方案:
<LinearLayout
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="wrap_content"
android:orientation="vertical"
>
<com.example.views.MaxHeightSwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxHeight="382dp">//size 382 = 300(RecyclerView) + 82 (addButton)
<com.example.views.MaxHeightNestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxHeight="382dp">
<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/appBackgroundColorLight"
android:orientation="vertical"
tools:background="@color/appBlue"
>
<com.example.views.MaxHeightRecyclerView
android:id="@+id/placesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="16dp"
android:scrollbarSize="2dp"
app:maxHeight="300dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="@color/colorAccent"
/>
<include layout="@layout/view_add_place_button"/>
</LinearLayout>
</com.example.views.MaxHeightNestedScrollView>
</com.example.views.MaxHeightSwipeRefreshLayout>
</LinearLayout>
Where MaxHeight*
view is from https://stackoverflow.com/a/48728490/2425851 MaxHeight*
视图来自https://stackoverflow.com/a/48728490/2425851
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.