在appbarlayout Android中隐藏tablayout



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

下面是我的代码

<?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>

所发生的是只滚动搜索栏位而不列出。我怎样才能滚动表格布局。我还注意到滚动和状态栏重叠。我想在状态栏下面滚动,如下所示-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>

最新更新