2016-11-28 4 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> 

하지만 아이콘과 텍스트 사이의 거리를 좋아하지 않는다. 큰. 이 두 가지 사이에 내 자신의 거리를 설정할 수 있습니까?

답변

0

직접적인 방법이 없다고 생각하기 때문에 사용자 정의 레이아웃을 탐색 용 서랍으로 직접 펼칠 수 있습니다. 사용자 정의 레이아웃에서 원하는 모든 작업을 수행 할 수 있습니다. 아이디어는 ImageView 및 TextView가 포함 된 목록 항목을 만들고 거리 (여백 또는 패딩)를 직접 설정할 수 있다는 것입니다. 여기

은 이제 res/layout 내부 drawer_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); 

을 팽창 방법은 다음과

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

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

ic_menu1을 드로어 블 디렉토리에 넣어야합니다. 그리고 회색 창에 대해서, 내용을 LinearLayout이나 Container RelativeLayout에 배경을 직접 설정할 수 있습니다.'android : id = "@ + id/navigation_drawer"' – HendraWD