[英]negative margin top in NavigationView layout
我有以下代碼的自定義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:fitsSystemWindows="true"
引起了您的問題。
嘗試刪除此行
刪除android:fitsSystemWindows="true"
。 該行告訴布局引擎使用整個屏幕放置元素,包括狀態欄下方的位。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.