<FrameLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<android.support.design.widget.NavigationView
android:id=“@+id/nav_view”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:layout_gravity=“start”
android:background=“@drawable/lanhua”
app:headerLayout=“@layout/nav_header”
app:menu=“@menu/nav_menu”>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
其中的FrameLayout布局就是用来放主屏幕的配置文件的,剩下的这个布局就是显示在滑动菜单的内容了,这边可以写任意的布局文件,上面的这个NavigationView也是谷歌官方的Design Support库中提供的一个控件,具体用法就上面这样,该控件也分为两部分显示,跟手机qq类似,这边需要注意的一个点是 这里控件的layout_gravity必须指定,我们需要告诉DrawerLayout滑动菜单是在屏幕的左边还是右边,指定left表示滑动菜单在左边,指定right表示滑动菜单在右边。这边指定为start,表示会根据系统语言进行判断,如果系统语言是从左往右的,比如英语,汉语,滑动窗口就在左边,如果系统语言是从右往左的,不如阿拉伯语,滑动窗口就在右边。
下面是他的header文件和menu文件。
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
android:layout_width=“match_parent”
android:padding=“10dp”
android:layout_height=“180dp”>
<de.hdodenhof.circleimageview.CircleImageView
android:id=“@+id/iconimage”
android:layout_width=“100dp”
android:layout_height=“100dp”
android:layout_centerInParent=“true”