【问题标题】:Header of NavigationView not showing unless there is margin to topNavigationView 的标题不显示,除非顶部有边距
【发布时间】:2017-07-30 19:05:46
【问题描述】:

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

为什么它不会按照标题布局中的定义显示?为什么需要推送布局才能显示?

【问题讨论】:

  • 您运行该应用的 android 版本是什么?
  • 你能在打开导航器的情况下添加图片吗?
  • @BrunoFerreira 我正在尝试在 android 5.1.1 上运行。我添加了一个带有大图像的图像视图,同样的事情发生了。我只能看到图像的下半部分,因为上半部分是隐藏的。这也让我意识到它隐藏在我手动添加的工具栏后面
  • 尝试通过使工具栏可见性消失来检查是否隐藏在工具栏后面。并且您在 drower 布局中添加工具栏?
  • @BrunoFerreira 你让我意识到问题出在工具栏上,并且问题已经在另一个问题中得到解决。如果你愿意,你可以用原始问题的链接来总结答案,我会接受你的答案。原问题:stackoverflow.com/questions/36826829/…

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


【解决方案1】:

根据 cmets 的理解,您得到了一个 ToolBar,它隐藏了内容,而不是一直停留在其上方。在此处查看此答案,它可能会解决您的问题:

Display content under toolbar

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-27
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    相关资源
    最近更新 更多