隐藏 appbarlayout 的 tablayout Android

hide tablayout of appbarlayout Android

我有 AppBarLayout,在协调器布局中带有搜索栏和 tablayout。同样在 appbarlayout 下面我有 viewpager。视图寻呼机内的片段具有滚动视图。我想滚动内容直到它的高度也滚动 AppBarLayout 。如果片段有更多内容,那么它应该将 AppBarLayout 滚动到视图之外。

下面是我的代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/purple"
android:orientation="vertical"
tools:context=".ui.BottomNavigationActivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/search_toolbar"
    android:background="@color/purple"
    android:elevation="0dp"
    android:fitsSystemWindows="true"
    android:layout_marginTop="@dimen/fragment_top_margin"
    android:paddingBottom="19dp"
    android:orientation="vertical"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|enterAlways">

    <include layout="@layout/custom_search_bar_home" />

    </androidx.appcompat.widget.Toolbar>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabRippleColor="@null"
        app:tabIndicatorColor="@null"
        app:tabTextAppearance="@style/TabTheme"
        app:tabSelectedTextColor="@android:color/white"
        app:tabTextColor="@color/whiteOpacity40"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:layout_scrollFlags="scroll|enterAlways"
        app:tabMaxWidth="0dp"
        app:tabPaddingStart="0dp"
        app:tabPaddingEnd="0dp">

    </com.google.android.material.tabs.TabLayout>
        </com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager.widget.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_white_round_top_corners20"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

发生的情况是只滚动搜索栏位而不是tablayout。我怎样才能滚动 tablayout。我还注意到滚动重叠状态栏。我希望像这样在状态栏下方滚动 - http://i.imgur.com/QHe92y7.gif

我可以通过将 AppBarLayout 的边距和填充移动到 Toolbar 和 TabLayout 来解决问题

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/purple"
android:orientation="vertical"
tools:context=".ui.BottomNavigationActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search_toolbar"
android:background="@color/purple"
android:elevation="0dp"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<androidx.appcompat.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    app:layout_scrollFlags="scroll|enterAlways"
    **android:layout_marginTop="@dimen/fragment_top_margin"**>

<include layout="@layout/custom_search_bar_home" />

</androidx.appcompat.widget.Toolbar>

<com.google.android.material.tabs.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabRippleColor="@null"
    app:tabIndicatorColor="@null"
    app:tabTextAppearance="@style/TabTheme"
    app:tabSelectedTextColor="@android:color/white"
    app:tabTextColor="@color/whiteOpacity40"
    app:tabMode="fixed"
    app:tabGravity="fill"
    app:layout_scrollFlags="scroll|enterAlways"
    app:tabMaxWidth="0dp"
    app:tabPaddingStart="0dp"
    app:tabPaddingEnd="0dp"
    **android:paddingBottom="19dp"**>

</com.google.android.material.tabs.TabLayout>
    </com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager.widget.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_white_round_top_corners20"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>