2015-12-19 49 views
0

我遇到了应用程序中折叠工具栏布局的预期滚动行为问题。为了确保我知道我在做什么,我创建了一个简单的测试项目,并能够达到预期的结果,但在该示例中使用了NestedScrollView,并且需要滚动的内容只是一个RelativeLayout,其中包含CardView以及大量文本。在真实应用程序的滚动内容是RecyclerView,我认为这是问题。就好像RecyclerView正在处理滚动一样,并且父级CollapsingToolbar不在循环中。CollapsingToolbarLayout不会折叠

请注意,app:layout_behavior="@string/appbar_scrolling_view_behavior"当前不在布局中。我曾尝试将它添加到各个地方,但没有获得理想的结果。

附加是一个应用程序的图像后,使用上面的折叠工具栏执行少量滚动而不会降低其高度。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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="match_parent" 
    tools:context=".ui.ArticleListActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/toolbar_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/Theme.AppBarOverlay"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/theme_primary" 
      app:contentScrim="@color/theme_primary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scaleType="centerCrop" 
       android:src="@drawable/empty_detail" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin"> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:contentDescription="@string/app_name" 
        android:src="@drawable/logo" /> 

      </android.support.v7.widget.Toolbar> 

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

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

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_refresh_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recycler_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

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

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

enter image description here

+0

尝试添加应用程序:layout_behavior =“@字符串/ appbar_scrolling_view_behavior”以回收视图以及/ –

+0

@AliHasanzade我试过了,但它导致RecyclerView移动到屏幕顶部。 – chris

回答

0

根据你的代码缺少什么,你必须设置滚动标志“滚动”到工具栏上面的ImageView的。 我已经做了类似的事情,并且您可以在下面的代码中看到,所有意图对RecyclerView滚动作出反应的视图都具有滚动标志,并且它们位于我们不想滚动的视图之前工具栏:

<android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="match_parent" 
      android:id="@+id/collapsingToolbar" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:contentScrim="?attr/colorPrimary" 
      > 

      <include layout="@layout/movie_details_header_layout" android:id="@+id/headerLayout" 
       app:layout_scrollFlags="scroll" 
       /> 

      <android.support.v7.widget.Toolbar 
       android:layout_height="56dp" 
       android:layout_width="match_parent" 
       android:id="@+id/toolbar" 
       app:navigationIcon="@drawable/ic_arrow_back" 
       android:navigationContentDescription="Back" 
       app:layout_collapseParallaxMultiplier="0.7" 
       app:layout_collapseMode="pin" 
       /> 
     </android.support.design.widget.CollapsingToolbarLayout> 


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

该项目使用版本22.x的compat库,更新到23似乎修复了一切。