王学岗AppBarLayout的

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    tools:context=".ThirdActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/tl_toolBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="0dp"
            android:background="#ffffff"
            app:contentInsetEnd="0dp"
            app:contentInsetEndWithActions="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:layout_scrollFlags="scroll">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@null">

                <ImageView
                    android:id="@+id/iv_banner3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scaleType="fitXY"
                    android:src="@mipmap/banner3" />

                <ImageView
                    android:id="@+id/back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="30dp"
                    android:src="@mipmap/back_white" />

                <TextView
                    android:id="@+id/tv_share"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="20dp"
                    android:layout_marginTop="30dp"
                    android:text="分享"
                    android:textColor="#ffffff" />

               
            </RelativeLayout>

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


        <android.support.design.widget.TabLayout
            android:id="@+id/tbl_three"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            app:tabIndicatorColor="@null"
            android:layout_gravity="center_vertical"
            app:tabBackground="@android:color/transparent"
            app:tabMode="fixed"
            app:tabSelectedTextColor="#21B8A9"
            app:tabTextColor="#999999">

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

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:layout_marginTop="10dp"
            android:background="#21B8A9" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp_show"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:overScrollMode="never"
        android:layout_height="match_parent"></android.support.v4.view.ViewPager>
    

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


ViewPager的适配器是三个RecyclerView,向上滑动RecylerView,会发现Toolbar会移除屏幕(ToolBar移出屏幕的五种情形),向下滑动RecyclerView ,ToolBar又会回到屏幕,另外TabLayout会一直停留在顶部
TabLayout停留在顶部的原因

猜你喜欢

转载自blog.csdn.net/qczg_wxg/article/details/82878122