3

目标是折叠toolbarSwipeRefreshLayout其中包含项目。为了能够使用支持库,我使用了CoordinatorLayout,其中托管了AppBarLayout。那AppBarLayout有一个toolbarSwipeRefreshLayout它有一个网格视图。使用app:layout_scrollFlags="scroll|enterAlways"折叠并打开toolbar没有问题,但是SwipeRefreshLayout不会一直滑动,即卡住。当从AppBarLayout中取出SwipeRefreshLayout时,它滚动的很好,但是这次工具栏不会折叠。下面是布局xml。任何帮助表示赞赏。android.support.v4.widget.SwipeRefreshLayout不会在android.support.design.widget.AppBarLayout中滑动

PS:我用this link为折叠式工具实现:

这里是我的布局:

<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> 
+0

Thanks Re AZ!伟大的编辑! –

+0

确保您使用的是最新的支持库。此外这是一个已知的用例,你尝试谷歌搜索:'coordinatorlayout swiperefresh'或类似的东西? –

+0

我对它进行了大量搜索。我发现的一个好答案是:http://stackoverflow.com/questions/30624138/android-coordinatorlayout-and-swiperefreshlayout这在我的情况下不起作用。我会尝试最新的支持库,因为我目前使用23.0.2。 –

回答

0

meybe android.support.v4.widget.SwipeRefreshLayout只支持的L​​inearLayout内

我的布局:

<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> 
相关问题