使用DrawerLayout的步骤有以下1几点:
1)在DrawerLayout中,第一个子View必须是显示内容的view,并且设置它的layout_width和layout_height属性是match_parent.
2)第二个view是抽屉view,并且设置属性layout_gravity="left|right",表示是从左边滑出还是右边滑出。设置它的layout_height="match_parent"
- <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/drawerlayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/textview"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:text="content" />
- <ListView
- android:id="@+id/listview"
- android:layout_width="80dp"
- android:layout_height="match_parent"
- android:layout_gravity="left"
- android:background="#FFB5C5" />
- </android.support.v4.widget.DrawerLayout>