<android.support.v4.widget.DrawerLayout
xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
<LinearLayout
android:id=“@+id/id_main_content”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>
<android.support.v7.widget.Toolbar
android:id=“@+id/id_toolbar”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background=“?attr/colorPrimary”
android:fitsSystemWindows=“true”
app:popupTheme=“@style/ThemeOverlay.AppCompat.Light”/>
<TextView
android:id=“@+id/id_tv_content”
android:layout_width=“match_parent”
android:layout_height=“0dp”
android:layout_weight=“1”
android:gravity=“center”
android:text=“HelloWorld”
android:textSize=“30sp”/>
<android.support.design.widget.NavigationView
android:id=“@+id/id_nv_menu”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_gravity=“start”
android:fitsSystemWindows=“true”
app:headerLayout=“@layout/header_just_username”
app:menu=“@menu/menu_drawer”
/>
</android.support.v4.widget.DrawerLayout>
DrawerLayout内部一个LinearLayout作为内容区域,一个NavigationView作为菜单。
注意下Toolbar的高度设置为wrap_content。
然后我们的NavigationView中又依赖一个布局文件和一个menu的文件。
header_just_username.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:layout_width=“match_parent”
android:layout_height=“192dp”
android:background=“?attr/colorPrimaryDark”
android:orientation=“vertical”
android:padding=“16dp”
android:fitsSystemWindows=“true”
android:theme=“