Header 的 NavigationView 不显示,除非顶部有边距
Header of NavigationView not showing unless there is margin to top
我正在创建一个 Android 应用程序,它在布局中有一个导航抽屉:
<?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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/navigation_select_layout"
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/navigation_drawer_header_layout"
app:menu="@menu/main_drawer_options" />
</android.support.v4.widget.DrawerLayout>
navigation_drawer_header_layout
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textViewButtonCloseDrawer"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="X"/>
</RelativeLayout>
添加了 header 布局但不显示,除非我为 TextView 添加上边距或向 RelativeLayout 添加一些填充以将 TextView 向下推。
为什么它不会按照 header 布局中的定义显示?为什么需要推送布局才能显示?
从评论中可以看出,您得到了一个 ToolBar
隐藏内容而不是始终停留在其上方。在此处查看此答案,它可能会解决您的问题:
我正在创建一个 Android 应用程序,它在布局中有一个导航抽屉:
<?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"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/navigation_select_layout"
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/navigation_drawer_header_layout"
app:menu="@menu/main_drawer_options" />
</android.support.v4.widget.DrawerLayout>
navigation_drawer_header_layout
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textViewButtonCloseDrawer"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="X"/>
</RelativeLayout>
添加了 header 布局但不显示,除非我为 TextView 添加上边距或向 RelativeLayout 添加一些填充以将 TextView 向下推。
为什么它不会按照 header 布局中的定义显示?为什么需要推送布局才能显示?
从评论中可以看出,您得到了一个 ToolBar
隐藏内容而不是始终停留在其上方。在此处查看此答案,它可能会解决您的问题: