即使在andorid中将fitsSystemWindows设置为true后,也无法避免填充问题

时间:2017-10-23 08:47:47

标签: android

代码如下。现在,fitsSystemWindows适用于应用栏,但下面代码中显示主要内容的帧布局,即使在使用fitsSystemWindows并将其设置为true时,也会获得应用栏下方的第一个元素。请帮助我理解为什么它不起作用。

  <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_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">


<!-- CoordinatorLayout is used to create scrolling and "floating" effects within a layout -->
<!-- This is typically the root layout which wraps the app bar and content -->
<android.support.design.widget.CoordinatorLayout


    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
    <!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:theme="@style/ToolbarTheme"
            app:layout_scrollFlags="scroll|enterAlways"
            android:minHeight="?attr/actionBarSize"
            app:titleTextColor="@android:color/white"
            app:popupTheme="@style/StyleForMyOverflowMenu">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="News"
                android:textColor="@color/white"
                android:textAppearance="?android:attr/textAppearanceMedium"/>

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <!-- The main content view where fragments are loaded -->
    <FrameLayout
        android:fitsSystemWindows="true"
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>

1 个答案:

答案 0 :(得分:0)

只需添加&#34; appbar_scrolling_view_behavior&#34;到FrameLayout并解决了问题

<!-- The main content view where fragments are loaded -->
        <FrameLayout
            android:fitsSystemWindows="true"
            android:id="@+id/flContent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />