【发布时间】: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