2016-03-19 18 views
2

Wie kann ich die Höhe einer Kopfzeile im NavigationView ändern? Ich habe nächsten xml: activity_main.xmlWie ändert man die Kopfhöhe in NavigationView?

<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"/> 

Aber NavigationView ignoriert alle Dimensionsattribute und zeigen einen Header mit Standardgrößen. Wie man es repariert?

Antwort

3

Sie müssen den Wert layout_height in Ihrer navigation_header.xml ändern.

Zum Beispiel wird dies die Kopfhöhe 100dp ändern:

<?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"/> 
+0

Wie kann ich wrap_content für 'ImageView' verwenden. Es funktioniert nicht mit 'NavigationView'. Meine 'ImageView' füllt die maximale Elternhöhe gleich. –

+0

Sorry, aber ich kann nicht verstehen, was Sie erreichen möchten. Kann deine Frage bearbeiten und erklären, was das erwartete Ergebnis ist, vielleicht mit einem Bild? –

Verwandte Themen