2015-11-05 120 views
0

我添加了一個CollapsingToolbarLayout,它將背景圖像放大並變形爲工具欄。我已經實現了代碼,它確實變成了工具欄,但問題是工具欄始終保持可見狀態,即使在collapsingToolbar佈局的ImageView的頂部,即使在非摺疊模式下,也可以看到。我不明白爲什麼會發生這種情況。以下是代碼:工具欄在Uncollapsed CollapsingToolbar頂部可見

<?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" 
    android:id="@+id/coordinatorLayoutForCollapsingBarActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="290dp" 
       android:fitsSystemWindows="true" 
       android:scaleType="fitXY" 
       android:src="@drawable/chicking_riding_converted" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/collapsingToolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:title="MyToolbarTitle" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf v jkljsdflk ajsdfkj asdklfj adsklfj asklfj adsklf jasdklfj ak fjasklfj adskl fjadkl fjadskl fjakl fjaksl fjakl fjasldk fjadskl fjask fjalfj adkfj asdkl fjaklf jasklfj aklf jadsklf jadslkf jadsklf jadkfl jasdlkf jaklf jadkl fjaskl fjasklf jadskl fjadsklf jaslk fjadslkf jaslkfjadslkfasjfkl jfklasdjfksfaklj asdklfj askl fjakl jflk jflk jalksdjf adsklfjasdklfj ads jfadskl jfadkfj adskl fjadklf jadsklf jakl fj k" 
      android:textAppearance="@android:style/TextAppearance.Material.Medium" /> 

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

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

這是什麼樣子:

enter image description here

是什麼原因造成的工具欄,以這樣的表現?

回答

0

嘗試設置

app:layout_collapseMode="parallax" 

Toolbar元件內部。

2

這是工具欄的背景。將其從工具欄中刪除:

android:background="?attr/colorPrimary" 

...並且它將是透明的。

如果崩潰時保持透明,這增加了CollapsingToolbarLayout:

app:contentScrim="?attr/colorPrimary" 

...,它會採用背景色崩潰時。