android - 如何更改 NavigationView 中的标题高度?

标签 android android-xml android-navigationview

如何更改 NavigationView 中的标题 View 高度?我有下一个 xml: activity_main.xml

<android.support.v4.widget.DrawerLayout
    android:id="@+id/dlDrawerContainer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".activity.MainActivity"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!-- Some data -->

    <!-- Drawer -->
    <android.support.design.widget.NavigationView
        android:fitsSystemWindows="true"
        android:id="@+id/nvNavigation"
        android:layout_width="wrap_content"
        android:maxWidth="400dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header"/>

</android.support.v4.widget.DrawerLayout>

navigation_header.xml

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
           android:src="@drawable/ic_header"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:maxWidth="400dp"
           android:maxHeight="100dp"
           android:scaleType="matrix"/>

但是 NavigationView 会忽略所有维度属性并显示具有默认大小的标题。如何解决?

最佳答案

您需要更改 navigation_header.xml 中的 layout_height 值。

例如,这会将页眉高度更改为 100dp:

<?xml version="1.0" encoding="utf-8"?>
<ImageView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_header"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:maxWidth="400dp"
    android:maxHeight="100dp"
    android:scaleType="matrix"/>

关于android - 如何更改 NavigationView 中的标题高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36105272/

相关文章:

Android:Ratingbar 步长低于 0.5

android - 如何从 Android Activity 导航到特定的 flutter 路由?

android - 如何从 strings.xml 中的字符串数组中获取字符串

android - 以编程方式设置工具栏高度Android

android - 找不到 R.Id。在 fragment 中

Android NavigationView 删除海拔

java - Android:低功耗蓝牙扫描器接收到空数据

android - 带导航图的抽屉导航不工作

java - Android NavigationView 抽屉没有关闭

Camera.open() 不工作安卓