SwipeRefreshLayout in AppBarLayout does not wrap content

I am trying to implement pull to update, but I have a problem with SwipeRefreshLayout without wrapping the height of the view of the child. In view view and in live assembly, it has 0 height.

The scheme is as follows:

 <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" app:elevation="0dp"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" app:layout_collapseMode="pin"> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_refresh_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> <include layout="@layout/child_layout" /> </android.support.v4.widget.SwipeRefreshLayout> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> 

I also tried making SwipeRefreshLayout parent element of AppBarLayout without any success, and also putting a single LinearLayout inside the SwipeRefreshLayout . The only thing that prevents the height of the wire layout from being 0 is to set it statically, but I want it to be dynamic, based on the height of the child view.

Is there something I am missing here? It looks like there might be a bug with SwipeRefreshLayout , because replacing it with LinearLayout , which also wraps the contents, works as expected.

+7
android android-layout swiperefreshlayout android-appbarlayout
source share
3 answers

The problem is that your SwipeRefreshLayout is inside the Toolbar and AppBarLayout . You should wrap the AppBarLayout with a different layout and place the SwipeRefreshLayout below the AppBarLayout . An example is given below.

 <android.support.design.widget.CoordinatorLayout 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" xmlns:tools="http://schemas.android.com/tools" android:fitsSystemWindows="true" tools:context="com.vsahin.moneycim.View.MainActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="250dp" android:theme="@style/ThemeOverlay.AppCompat.Dark" android:fitsSystemWindows="true" app:expanded="false"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary" android:fitsSystemWindows="true" android:background="@drawable/gradient_background"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:layout_scrollFlags="scroll|enterAlways" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.SwipeRefreshLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </android.support.v4.widget.SwipeRefreshLayout> </android.support.design.widget.CoordinatorLayout> 
+4
source share

if the height of the SwipeRefreshLayout wraps the contents of your child_layout , then the height of your child_layout must be set to match_parent , or both SwipeRefreshLayout and child_layout height must be set to match_parent as shown in the Android Documentation

 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swiperefresh" android:layout_width="match_parent" android:layout_height="match_parent"> <!--Child View--> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v4.widget.SwipeRefreshLayout> 
+1
source share

SwipeRefreshLayout is a transparent View , so the best solution for setting it match_parent it will not conflict with other views and does not include View or Layout in it, keep it clean

 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_refresh_layout" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" app:elevation="0dp"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" app:layout_collapseMode="pin"> <include layout="@layout/child_layout" /> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> 

SwipeRefreshLayout must be on top to overlay other layers and be clickable

0
source share

All Articles