2016-12-26 4 views
0

Ich versuche, eine Navigationsschublade für alle meine Aktivitäten zu erstellen. Ich benutze Android Studio und erzeuge eine Navigationsschubladenaktivität. Meine anderen Aktivitäten erstrecken sich darin, um die Navigationsschublade zu bekommen. Ich füge ein Pictue mit der Android Studio Funktion ein und existiere nun die hdpi und xhdpi ... im "mipmap" Ordner.Android: Navigationsschublade Header Image

ich in dem Navigation Header-Layout-Hintergrund mein eingefügtes Bild ändern:

android:background="@mipmap/ic_lmg_bck" 

nav_header_nd.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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="@dimen/nav_header_height" 
    android:background="@mipmap/ic_lmg_bck" 
    android:gravity="bottom" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     app:srcCompat="@drawable/ic_launcher" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:text="Nutzername" 
     android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Nutzernameemail" /> 

</LinearLayout> 

Alle Arbeiten, aber das Bild ist verwackelt und zu klein:

Screenshot

Original Bild:

original

Wie es möglich ist, die Größe des Bildes?

+0

versuchen das Image der Scaletype Eigenschaft zu ändern – Manny265

Antwort

1

Um den Hintergrund hinzuzufügen, müssen Sie nur Ihr Bild in den Zeichnungsordner kopieren (fügen Sie das Bild nicht mit "add new Image Asset" hinzu).

Danach gehen Sie zu Ihrem: nav_header_nd.xml

und ändert Hintergrund:

android:background="@drawable/mypicture" 
0

This thread geht es darum, wie Sie Zeichnungsdateien richtig implementieren.

Am Ende sollten Sie ein Bild mit hoher Auflösung haben. Ich kann sehen, dass Sie die ic_launcher-Funktion verwendet haben, die es in Symbol-Auflösungen konvertiert.

+0

Danke für die Hilfe. Ich habe es getestet, aber bei 1. habe ich nur Bilder gegraut. Ich versuchte es zu lösen wie: http://stackoverflow.com/questions/28807121/android-icon-generator-for-actionbar-and-notification-not-working-grey-shape Das Bild war nicht grau, aber es war " schlimmer als vorher. – Excel1

+0

Ich weiß es richtig. Ich hatte das gleiche Problem. Sie müssen es in den Ordner verschieben. Jemand weiter unten erklärt es, denke ich. – creativecreatorormaybenot

+0

ich ersetzte die Bilder mit korrekt gerendert aber es half nicht – Excel1

0

Hier ist der Code, den ich verwenden, ist es wenig angepasste navigationView:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/content_home" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:scaleType="centerCrop" 
      android:layout_weight="1" /> 

     <LinearLayout 
      android:id="@+id/ll_feedback" 
      style="@style/Navigation_linear"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="44dp" 
       android:src="@drawable/feedback" /> 

      <TextView 
       style="@style/Navigation_text" 
       android:text="Give us feedback" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/ll_share_app" 
      style="@style/Navigation_linear"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="44dp" 
       android:src="@drawable/faq" /> 

      <TextView 
       style="@style/Navigation_text" 
       android:text="Share app" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/ll_rate_app" 
      style="@style/Navigation_linear"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="44dp" 
       android:src="@drawable/rate" /> 

      <TextView 
       style="@style/Navigation_text" 
       android:text="Rate app" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/ll_setting" 
      style="@style/Navigation_linear"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="44dp" 
       android:src="@drawable/setting" /> 

      <TextView 
       style="@style/Navigation_text" 
       android:text="Settings" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/ll_notifications" 
      style="@style/Navigation_linear"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="44dp" 
       android:src="@drawable/notification" /> 

      <TextView 
       style="@style/Navigation_text" 
       android:text="Notifications" /> 
     </LinearLayout> 

     <ImageView 
      android:id="@+id/backNavigation" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_marginBottom="72dp" 
      android:layout_marginLeft="16dp" 
      android:adjustViewBounds="true" 
      android:background="?attr/selectableItemBackground" 
      android:clickable="true" 
      android:padding="24dp" 
      android:src="@drawable/arrow_left" /> 
    </LinearLayout> 
</android.support.design.widget.NavigationView> 

Probieren Sie es aus, und lassen Sie mich wissen, ob es hilft.

+0

Danke für Hilfe. Ich habe es versucht, aber ich habe viele Fehler (fehlende Strings ...). Und das Image bleibt gleich. Am Image ändert sich nichts, also hat es nicht funktioniert. – Excel1

+0

@ Excel1 entfernen Sie das Tag und Sie müssen Ihre eigene Zeichenfolge verwenden. Die erste ImageView-Navigationsansicht ist Ihre Kopfzeile. Sie müssen NavigationView auch in Ihrer Java-Datei initialisieren. –

+0

@ Excel1 Versuchen Sie diese [link] (http://www.android4devs.com/2015/06/navigation-view-material-design-support.html) –

Verwandte Themen