简单代码实现向上滑动隐藏标题栏

来源:互联网 发布:钢琴谱打印软件 编辑:程序博客网 时间:2024/06/05 03:44

首先加依赖

  compile "com.android.support:design:22.2.1"

然后在布局里面写,就能实现了

<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:fitsSystemWindows="true">    <android.support.design.widget.CoordinatorLayout        android:layout_width="match_parent"        android:layout_height="match_parent">        <android.support.v4.widget.NestedScrollView            android:layout_width="match_parent"            android:layout_height="match_parent"            app:layout_behavior="@string/appbar_scrolling_view_behavior">            //这里放内容        </android.support.v4.widget.NestedScrollView>        <android.support.design.widget.AppBarLayout            android:layout_width="match_parent"            android:layout_height="wrap_content">            <android.support.v7.widget.Toolbar                android:id="@+id/toolbar"                android:layout_width="match_parent"                android:layout_height="@dimen/bar_height"                android:background="@drawable/bg"                android:minHeight="@dimen/bar_height"                app:layout_scrollFlags="scroll|enterAlways"           >                <TextView                    android:textColor="@color/white"                    android:text="标题"                    android:textSize="17sp"                    android:layout_gravity="center"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerInParent="true" />            </android.support.v7.widget.Toolbar>        </android.support.design.widget.AppBarLayout>    </android.support.design.widget.CoordinatorLayout></RelativeLayout>
0 0
原创粉丝点击