Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change header height in NavigationView?

How can I change a header view height in the NavigationView? I have next 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"/>

But NavigationView ignores all dimension attributes and shows a header with default sizes. How to fix it?

like image 276
Шах Avatar asked Sep 14 '25 19:09

Шах


1 Answers

You need to change the layout_height value in your navigation_header.xml.

For example this will change the header height to 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"/>
like image 129
Mattia Maestrini Avatar answered Sep 16 '25 10:09

Mattia Maestrini