私はそれを行う直接的な方法はないと思うので、カスタムレイアウトをナビゲーションドロワーに直接展開することができます。カスタムレイアウトから、あなたは何でもできます。アイデアは、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);
を膨らませる方法をここで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>
メニューはグレーのウィンドウで塗装されていることを確認することができます
drawer_content.xml
の一例です。ここでエラーが発生します。android:src = "@ drawable/ic_menu1" /> –あなたはdrawableディレクトリの中にic_menu1を持っているはずです。グレーのウィンドウについては、コンテンツをLinearLayoutに直接設定するか、RelativeLayoutコンテナを 'android:id =" @ + id/navigation_drawer "'で設定することができます – HendraWD