Android 设计支持 TabLayout 重叠内容 [英] Android Design Support TabLayout overlapping content
问题描述
我正在使用设计支持库中引入的新 TabLayout.我有这样的代码:
I am using the new TabLayout introduced in the design support library. I have the code like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/lines_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
问题是,选项卡与片段显示的内容顶部重叠.我怎样才能解决这个问题?我在 Github 上的示例中使用 TabLayout,所以我相信我的代码没有问题.我已经有一个工具栏,因为我使用了导航抽屉中片段中的选项卡,所以我从 AppBarLayout 中删除了它.
The problem is, that the tabs overlap the top of the content the fragments display. How can I fix this? I am using the TabLayout like in the examples on Github, so I believe there is no issue with my code. I already have a Toolbar because I use the tabs in a fragment in a navigation drawer, so I removed it from the AppBarLayout.
推荐答案
您需要将 app:layout_behavior="@string/appbar_scrolling_view_behavior"
添加到您的 ViewPager
: this是将视图的高度更改为低于 AppBarLayout
而不是完整的 match_parent
高度.
You need to add app:layout_behavior="@string/appbar_scrolling_view_behavior"
to your ViewPager
: this is what changes the height of the View to be below the AppBarLayout
rather than the full match_parent
height.
这篇关于Android 设计支持 TabLayout 重叠内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!