learner
learner

Reputation: 11780

make toolbar go away in CollapsingToolbarLayout

How do I keep the toolbar from pinning in a collapsing toolbar layout? Here is the entire layout. No matter what I set app:layout_collapseMode to, it still pins. I want the toolbar to disappear and then reappear when user starts scrolling back down again.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="256dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        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:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            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="none"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

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

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>

Upvotes: 0

Views: 780

Answers (1)

DmitryArc
DmitryArc

Reputation: 4837

You should use app:layout_scrollFlags="scroll|enterAlways" instead of app:layout_scrollFlags="scroll|exitUntilCollapsed" inside your CollapsingToolbarLayout.

And with app:layout_collapseMode attribute of the ImageView you just specify the visual effect of how this view will be collapsed.

More info about these attributes you can find in the official documentation: layout_scrollFlags and layout_collapseMode

Upvotes: 3

Related Questions