2016-11-28 17 views
0

は、私は私のナビゲーションメニューで次の項目を表示:ナビゲーション・ドロワーのアイコンとアイテム・タイトルの間の距離を変更できますか?

<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@+id/nav_locate" 
    android:icon="@mipmap/ic_add_location_black_24dp" 
    android:title="Localizare" /> 

    <item android:id="@+id/nav_propose" 
android:icon="@mipmap/ic_landscape_black_24dp" 
android:title="Obiective" /> 

    <item android:id="@+id/nav_propose" 
android:icon="@mipmap/ic_settings_black_24dp" 
android:title="Setari" /> 

</menu> 

しかし、私はアイコンとテキストの間の距離を好きではありません。大きくなる。これら2つのことの間に自分の距離を置くことはできますか?

答えて

0

私はそれを行う直接的な方法はないと思うので、カスタムレイアウトをナビゲーションドロワーに直接展開することができます。カスタムレイアウトから、あなたは何でもできます。アイデアは、ImageViewとTextViewを含むリストアイテムを作成し、それらに直接距離(マージンまたはパディング)を設定できるということです。ここで

は、カスタムレイアウトが今、あなたはres/layoutdrawer_content.xmlを作成し、あなたが望むようなレイアウトを作る

RelativeLayout drawer = (RelativeLayout) findViewById(R.id.navigation_drawer); 
View drawerContent = getLayoutInflater().inflate(R.layout.drawer_content, null); 
drawerContent.setLayoutParams(new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.MATCH_PARENT, 
    RelativeLayout.LayoutParams.MATCH_PARENT)); 
drawer.addView(drawerContent); 

を膨らませる方法をここでDrawerLayout

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Main content --> 
    <RelativeLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <!-- Insert any views you want as main content --> 
    </RelativeLayout> 

    <!-- Navigation drawer --> 
    <RelativeLayout 
     android:id="@+id/navigation_drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" /> 

</android.support.v4.widget.DrawerLayout> 

の一例です。 は、ここでは、

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="8dp" 
      android:src="@drawable/ic_menu1" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:text="Menu 1" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="8dp" 
      android:src="@drawable/ic_menu2" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:text="Menu 2" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="8dp" 
      android:src="@drawable/ic_menu3" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:text="Menu 3" /> 
    </LinearLayout> 

</LinearLayout> 
+0

メニューはグレーのウィンドウで塗装されていることを確認することができますdrawer_content.xmlの一例です。ここでエラーが発生します。android:src = "@ drawable/ic_menu1" /> –

+0

あなたはdrawableディレクトリの中にic_menu1を持っているはずです。グレーのウィンドウについては、コンテンツをLinearLayoutに直接設定するか、RelativeLayoutコンテナを 'android:id =" @ + id/navigation_drawer "'で設定することができます – HendraWD

関連する問題