简体   繁体   English

使用CoordinatorLayout滚动隐藏工具栏

[英]Hide Toolbar on scroll with CoordinatorLayout

My app's action bar consists of a Toolbar and a tab view with a ViewPager to display the page's content. 我的应用程序的操作栏包含Toolbar和带有ViewPager的标签视图,以显示页面的内容。 I am using a CoordinatorLayout so that I can hide the Toolbar on scroll, but it isn't hiding. 我正在使用CoordinatorLayout以便我可以隐藏Toolbar滚动,但它没有隐藏。 Here is my activity_main.xml: 这是我的activity_main.xml:

<?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:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:fitsSystemWindows="true"
                app:contentInsetEnd="0dp"
                app:contentInsetStart="0dp"
                app:layout_scrollFlags="scroll|enterAlways">

                <include layout="@layout/actionbar" />
            </android.support.v7.widget.Toolbar>

            <com.whatsgoodly.views.SlidingTabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/purple"
                app:layout_scrollFlags="scroll|enterAlways" />
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp”
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

Any thoughts? 有什么想法吗?

将其添加到您的android.support.v7.widget.Toolbar标记:

app:layout_collapseMode="parallax"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM