微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

隐藏appbarlayout Android的tablayout

如何解决隐藏appbarlayout Android的tablayout

我在协调器布局中有带有搜索栏和 tablayout 的 AppBarLayout。同样在 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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。