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

时间:2016-03-19 18:06:10

标签: android android-xml android-navigationview

如何更改NavigationView中的标题视图高度?我有下一个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会忽略所有维度属性,并显示默认大小的标头。如何解决?

2 个答案:

答案 0 :(得分:3)

您需要更改 navigation_header.xml 中的https://maps.googleapis.com/maps/api/place/textsearch/json?query=Meenakshi+Amman+Temple,+Madurai,+Tamil+Nadu+625001&key=<API KEY HERE>值。

例如,这会将标题高度更改为100dp:

layout_height

答案 1 :(得分:0)

已经很晚了,但我发现它很有用。
1-尝试将ImageView放入FrameLayout之类的容器中
2-然后设置FrameLayout的宽度和高度"match_parent"
3-也将ImageView的高度设置为"match_parent"
4-将adjustViewBounds = "true"添加到ImageView
5-将maxHeight = "100dp"添加到ImageView
因此将ImageView设置为"match_parent",但高度最后达到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>
相关问题