【发布时间】:2016-03-03 13:55:26
【问题描述】:
我在使用包含 AppBarLayout(包含 ToolBar 和 TabLayout)和 ViewPager(包含片段)作为子级的 Coordinator 布局时遇到问题。我希望在向下滚动时隐藏顶栏,并在向上滚动时显示。但是,当我向下滚动时,状态栏也会向上滚动,将顶部栏留在状态图标下方,被它们重叠。
我尝试将 android:fitsSystemWindows="true" 添加到 AppBarLayout 和 ViewPager 但没有任何改变。
下面是使用的代码和显示两种状态的快照:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
我遇到了同样的问题,我能够解决它,但我没有代码!几种可能性:a)
fitsSystemWindows="true"在您的AppBarLayout上,b) 将contentScrim添加到您的AppBarLayout或Toolbar(app:contentScrim="@color/primaryDark"),或 c) 尝试使用CollapsingToolbarLayout而不是AppBarLayout,但不要给它折叠滚动标志。希望其中之一有所帮助!
标签: android xml android-layout android-coordinatorlayout