2016-12-26 2 views
0

すべての自分のアクティビティー用のナビゲーション・ドロワーを作成しようとしています。私はAndroid Studioを使用し、ナビゲーション引き出しアクティビティを生成します。私の他のアクティビティは、ナビゲーション・ドロワーを得るためにそれの中に広がっています。私はAndroidスタジオ機能とPictueを挿入し、現在 "ミップマップ"フォルダにhdpiとxhdpi ...が存在します。Android:ナビゲーションドロワーヘッダー画像

私が挿入した画像へのナビゲーションヘッダーのレイアウトの背景に変更します。

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> 

すべての作品が、画像が不鮮明と小型であり:

Screenshot

オリジナル画像:

original

それはイメージのサイズを変更することが可能になる方法は?

+0

は助けてくれてありがとう – Manny265

答えて

1

バックグラウンドを追加するには、画像をドロウアブルフォルダにコピー/ペーストする必要があります(「新しい画像資産の追加」で画像を追加しないでください)。あなたに行くこの後

:nav_header_nd.xml

とに背景を変更:

android:background="@drawable/mypicture" 
0

This threadは、正しい方法でドロワーブルを実装する方法です。

最後に高解像度の画像が必要です。アイコン解像度に変換するic_launcher機能を使用したことがわかります。ここで

+0

ImageViewののscaleTypeプロパティを変更してみてください。私はそれをテストしましたが、1で私は灰色の絵だけを得ました。私はそれを解決しようとしました:http://stackoverflow.com/questions/28807121/android-icon-generator-for-actionbar-and-notification-not-working-grey-shape 画像はグレーではありませんでしたが、前よりも悪い "。 – Excel1

+0

私は正しいことを知っています。私は同じ問題を嫌う。それをフォルダに移動する必要があります。さらに詳しい人は私がそれを説明していると思う。 – creativecreatorormaybenot

+0

私は正しくレンダリングされた画像を置き換えましたが、それは役に立たなかった – Excel1

0

は、私が使用するコードです、それは少しカスタマイズ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> 

はそれを試してみて、それが助けなら、私に知らせてください。

+0

助けてくれてありがとう。私はそれを試してみましたが、私は多くのエラー(文字列がありません...)があります。そしてイメージは同じままです。画像で何も変わらないので、うまくいきませんでした。 – Excel1

+0

@ Excel1 タグを削除してください。独自の文字列を使用する必要があります。ナビゲーションビュー内の最初のImageViewはヘッダーです。また、JavaファイルでNavigationViewを初期化する必要があります。 –

+0

@ Excel1この[リンク]を試してください(http://www.android4devs.com/2015/06/navigation-view-material-design-support.html) –