CoordinatorLayout + AppBarLayout+ToolBar 实现向上滚动隐藏 ToolBar

【需求】

3793005-beafa8fa82c64be6.png
图片.png

【传送门】 https://www.jianshu.com/p/9e126f3538a0
【xml 布局 】

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
    android:fitsSystemWindows="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/shell_appbarlayout_style"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            app:layout_scrollFlags="scroll|enterAlways"
            android:id="@+id/toolbar"
            android:paddingTop="6dp"
            android:layout_width="match_parent"
            android:layout_height="35dp">

        <ImageView
            android:id="@+id/iv_home_tab_logo"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/shell_home_actionbar_logo"/>

        </android.support.v7.widget.Toolbar>


        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <android.support.design.widget.TabLayout
            android:id="@+id/tbl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="@color/colorAccent"
            app:tabPaddingEnd="6dp"
            app:tabPaddingStart="6dp"
            app:tabSelectedTextColor="@color/shell_font_black"
            android:layout_marginRight="35dp"
            app:tabTextColor="@color/shell_font_gray"/>

            <ImageView
                android:id="@+id/iv_home_tab_more"
                android:layout_gravity="end|center_vertical"
                android:background="@color/shell_divide_line_gray"
                android:padding="6dp"
                android:layout_marginRight="8dp"
                android:layout_marginLeft="60dp"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/shell_home_tab_more"/>

        </FrameLayout>

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:background="@color/shell_divide_line_gray" />

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

    <LinearLayout
        android:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
            android:id="@+id/vp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v4.view.ViewPager>
    </LinearLayout>

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

猜你喜欢

转载自blog.csdn.net/weixin_34358365/article/details/86807997