您的位置:首页 > 编程语言

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

2015-12-30 14:15 501 查看

首先加依赖

[code]  compile "com.android.support:design:22.2.1"


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

[code]<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: