折叠collapsingtoobarlayout时隐藏工具栏

时间:2018-03-07 07:05:16

标签: android toolbar android-collapsingtoolbarlayout

我想要实现的是在滚动我的recyclerview时隐藏collapsingtoolbarlayout并在进一步滚动时折叠maintoolbar。但我只能达到这个http://i.imgur.com/t6wTW5H.gif

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:layout_scrollFlags="scroll|snap|enterAlways" />
</android.support.design.widget.AppBarLayout>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/id_toolbar_container"
    app:layout_scrollFlags="scroll|snap|enterAlways"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|snap|enterAlways">

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize" />
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/sample"/>
    </android.support.v4.view.ViewPager>

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

所以我不能超越这个

如果我进一步滚动,我也想隐藏我的工具栏。

1 个答案:

答案 0 :(得分:0)

基本上,您的根布局必须是CoordinatorLayout

查看Github上的 cheesesquare 示例项目,了解详细信息。