Android Toolbar collapseMode issue

南笙酒味 提交于 2019-11-28 09:24:21

try this...

You have to use app:layout_scrollFlags="scroll|exitUntilCollapsed" instead of app:layout_scrollFlags="scroll|enterAlways" inside the CollapsingToolbarLayout

and use app:layout_collapseMode="pin" inside the toolbar

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

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="250dp"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" >

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#20000000" />
        </FrameLayout>

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Application Title"
                android:textColor="#fff"
                android:textSize="18sp" />
        </android.support.v7.widget.Toolbar>

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

In your toolbar do this:

app:layout_collapseMode="pin"

pin is used for pinning the layout to top when the collapsing toolbar layout scrolls

parallax is used for hiding the layout when collapsing toolbar scrolls to top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!