직접적인 방법이 없다고 생각하기 때문에 사용자 정의 레이아웃을 탐색 용 서랍으로 직접 펼칠 수 있습니다. 사용자 정의 레이아웃에서 원하는 모든 작업을 수행 할 수 있습니다. 아이디어는 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>
메뉴가 회색 창에 그려진 할 수
drawer_content.xml
의 예입니다. 여기에 오류가 발생합니다. android : src = "@ drawable/ic_menu1"/> –ic_menu1을 드로어 블 디렉토리에 넣어야합니다. 그리고 회색 창에 대해서, 내용을 LinearLayout이나 Container RelativeLayout에 배경을 직접 설정할 수 있습니다.'android : id = "@ + id/navigation_drawer"' – HendraWD