3

The goal is to have a collapsing toolbar and a SwipeRefreshLayout which has items. To be able to use the support library, I use CoordinatorLayout which hosts an AppBarLayout. That AppBarLayout has a toolbar and SwipeRefreshLayout which has a grid view. Using app:layout_scrollFlags="scroll|enterAlways" there is no problem with collapsing and opening the toolbar, however SwipeRefreshLayout does not swipe all the way down, i.e., it is stuck. When taking the SwipeRefreshLayout out of AppBarLayout, it scrolls fine but this time the toolbar does not collapse. below is the layout xml. any help is appreciated.

PS: I used this link for collapsing toolbar implementation:

Here's my layout:

<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_height="match_parent"                                                                             
    android:layout_width="match_parent">                                                                

    <android.support.design.widget.AppBarLayout                                                                      
        android:id="@+id/appBarLayout"                                                                               
        android:layout_width="match_parent"                                                                          
        android:layout_height="wrap_content">                                                                        

        <android.support.v7.widget.Toolbar                                                                               
            android:id="@+id/toolbar"                                                                                    
            android:layout_width="match_parent"                                                                          
            android:layout_height="50dp"                                                                                 
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"                                                     
            android:background="@color/primary_dark"                                                                     
            app:layout_scrollFlags="scroll|enterAlways">                                                                                                                                             
        </android.support.v7.widget.Toolbar>                                                                             

        <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"                                                                         
            app:layout_behavior="@string/appbar_scrolling_view_behavior">                                                

            <GridView                                                                                                    
                android:id="@+id/gridview"                                                                               
                android:layout_width="match_parent"                                                                      
                android:layout_height="match_parent"                                                                     
                android:verticalSpacing="2dp"                                                                            
                android:horizontalSpacing="2dp"                                                                          
                android:paddingLeft="@dimen/activity_horizontal_margin"                                                  
                android:paddingRight="@dimen/activity_horizontal_margin"                                                 
                android:paddingTop="@dimen/activity_vertical_margin"                                                     
                android:paddingBottom="@dimen/activity_vertical_margin"                                                  
                android:stretchMode="columnWidth"                                                                        
                android:numColumns="2"/>                                                                                                                                                           
        </android.support.v4.widget.SwipeRefreshLayout>                                                                  

    </android.support.design.widget.AppBarLayout>                                                                    

</android.support.design.widget.CoordinatorLayout> 
Reaz Murshed
  • 21,071
  • 12
  • 69
  • 87
erol yeniaras
  • 3,463
  • 2
  • 18
  • 37
  • Thanks Reaz! Great edit! – erol yeniaras Oct 11 '16 at 06:26
  • Make sure you are using latest support library. Also this is a known usecase, did you try googling: 'coordinatorlayout swiperefresh' or something like this? – Michał Z. Oct 12 '16 at 20:14
  • I googled it extensively. One of the good answers that I found was : http://stackoverflow.com/questions/30624138/android-coordinatorlayout-and-swiperefreshlayout which did not work in my case. I will try the latest support library since I am using 23.0.2 at the moment. – erol yeniaras Oct 12 '16 at 21:37

1 Answers1

-2

meybe android.support.v4.widget.SwipeRefreshLayout only support Linearlayout inside

my layout:

  <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/iv_main"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:src="@drawable/cat"/>
    </LinearLayout>
</com.activity.com.swiperfreshlayout.PullToRefreshScrollView>