2015-12-19 116 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似乎修復了一切。