actionbar重叠片段内容

时间:2016-01-17 10:59:03

标签: android android-layout android-actionbar

我使用导航栏切换我的片段,但片段内容总是被操作栏重叠,如何避免这种情况?

我尝试删除行android:fitsSystemWindows="true",但它没有改变任何内容。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <!-- Framelayout to display Fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" />

    <include
        layout="@layout/app_bar_violation_browser"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_violation_browser"
        app:menu="@menu/activity_violation_browser_drawer" />

</android.support.v4.widget.DrawerLayout>

这里我放置了4个文本行

enter image description here

但是当我在我的设备上运行时,它看起来像这样......

enter image description here

2 个答案:

答案 0 :(得分:1)

因为<android.support.v4.widget.DrawerLayout>内有3个观看次数,所以只有第一个被视为内容,其他两个被视为抽屉。

FrameLayout标识为frame_container,将include标注为app_bar_violation_browser另一个FrameLayout。

答案 1 :(得分:0)

尝试将以下代码添加到片段布局中:

   android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"

特别是marginTop!

并且,像这样使用<include并在引用布局上做你的事情:

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

并删除FrameLayout并在Include中使用它。

那应该适用。