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?
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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With