Android 如何在NavigationView中更改标题高度?

Android 如何在NavigationView中更改标题高度?,android,android-xml,android-navigationview,Android,Android Xml,Android Navigationview,如何在NavigationView中更改页眉视图高度?我有下一个xml: 活动\u 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"

如何在
NavigationView
中更改页眉视图高度?我有下一个xml: 活动\u 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>
<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"/>

导航_header.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>
<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
忽略所有维度属性,并显示带有默认大小的标题。如何修复它?

您需要更改导航标题.xml中的
布局高度值

例如,这会将收割台高度更改为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"/>

虽然很晚了,但我发现它很有用。
1-尝试将ImageView放入容器中,如
FrameLayout

2-然后设置FrameLayout的宽度和高度
“匹配父项”

3-将
ImageView
的高度也设置为
“匹配父项”

4-将
adjustViewBounds=“true”
添加到ImageView
5-将
maxHeight=“100dp”
添加到ImageView
因此,通过这种方式,ImageView被设置为“匹配父项”
,但它的高度最后达到了100dp

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
             android:layout_height="match_parent">

    <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:srcCompat="@mipmap/ic_launcher"
            android:id="@+id/imageView"
            android:adjustViewBounds="true" 
            android:maxHeight="100dp"/>
</FrameLayout>


如何为
ImageView
使用wrap\u内容。它不适用于
导航视图
。我的
ImageView
填充的最大父级高度相同。抱歉,我无法理解您想要实现的目标。可以编辑您的问题并澄清预期结果是什么,也许可以使用图像?