【问题标题】:negative margin top in NavigationView layoutNavigationView 布局中的负边距顶部
【发布时间】:2018-07-24 16:44:35
【问题描述】:

我有以下代码的自定义 DrawerLayout。 我不知道为什么我的布局 (drawer_layout) 从顶部占了边距,并且您可以在下面看到的红色关闭按钮被覆盖。

<?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"
tools:context=".DashboardActivity"
android:layout_gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">

[Some other elements here ...]


<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginRight="-64dp"
    android:fitsSystemWindows="true">

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

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

它是我为 NavigationView 定制的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:background="@color/primary_color"
android:layout_height="match_parent">

<ImageView
     [Properties]
 />

<TextView

    [Properties]
    />

<TextView

    [Properties]
    />

<ImageView
     [Properties]
 />

<ImageButton
    android:id="@+id/drawer_close_image_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginTop="8dp"
    android:background="@drawable/radius_background_acent_color"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_close_black_24dp" />

</android.support.constraint.ConstraintLayout>

但结果我有一个负边距顶部,如下图所示。

如何从顶部移除该边距并正确显示我的 NavigationView 布局?

【问题讨论】:

    标签: android navigation-drawer navigationview


    【解决方案1】:

    删除android:fitsSystemWindows="true"。该行告诉布局引擎使用整个屏幕放置元素,包括状态栏下方的位。

    【讨论】:

      【解决方案2】:

      我认为是android:fitsSystemWindows="true" 导致了您的问题。

      尝试删除此行

      【讨论】:

        猜你喜欢
        • 2018-07-20
        • 1970-01-01
        • 1970-01-01
        • 2021-05-27
        • 2015-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-01
        相关资源
        最近更新 更多