android - 除非顶部有边距,否则 NavigationView 的标题不显示

标签 android android-layout navigation-drawer android-navigationview

我正在创建一个在布局中有抽屉导航的 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>

标题布局已添加但不显示,除非我为 TextView 添加上边距或向 RelativeLayout 添加一些填充以将 TextView 向下推。

为什么它不会按照页眉布局中的定义显示?为什么需要插入布局才能显示?

最佳答案

从评论中可以看出,您得到了一个 ToolBar,它隐藏了内容,而不是始终位于其上方。在此处查看此答案,它可能会解决您的问题:

Display content under toolbar

关于android - 除非顶部有边距,否则 NavigationView 的标题不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45398421/

相关文章:

android - jQuery Mobile 中的文本区域

android - 在 ScrollView 中列出

android - 如何在 Android LinearLayout 周围创建边框?

android - 我可以找出需要在屏幕上显示的字符串的 dp 或 px 大小吗?

android - 如何为抽屉导航菜单项设置多行?

android - 抽屉导航列表中的下划线菜单项

android - 构建大小大于 100 Mb 的 android 应用程序

android - 所选的画廊默认项目位于中心

Android - 包括来自另一个模块的布局

java - 抽屉导航选择的项目不显示第二组项目的背景颜色