工具栏在Uncollapsed CollapsingToolbar顶部可见

时间:2015-11-05 14:43:18

标签: android xml toolbar android-collapsingtoolbarlayout

我添加了一个CollapsingToolbarLayout,它可以褪色背景图像并变形到工具栏。我已经实现了代码,它确实变形为一个工具栏,但问题是工具栏始终保持可见,甚至在collapsingToolbar布局的ImageView顶部,甚至在未收集模式。我不明白为什么会这样。以下是代码:

<?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

是什么导致工具栏的行为如此?

2 个答案:

答案 0 :(得分:2)

这是工具栏背景。从工具栏中删除它:

android:background="?attr/colorPrimary"

......它会透明。

如果在折叠时它保持透明,请将其添加到CollapsingToolbarLayout:

app:contentScrim="?attr/colorPrimary"

...它会在折叠时采用背景色。

答案 1 :(得分:0)

尝试设置

app:layout_collapseMode="parallax"

Toolbar元素内。