Drawerlayout can achieve the left and right sliding function, as long as the layout file is configured around two drawers can be, about two drawers can be any view, combined with Navigationview can be very good to achieve the function of the side-slide menu
To use Drawerlayout, need v4 package, use Navigationview, need V7 package;
--------------------------------------------Layout------------------------------------------------
<?xml version= "1.0" encoding= "Utf-8"?>
<android.support.v4.widget.drawerlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
xmlns:app= "Http://schemas.android.com/apk/res-auto"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
tools:context= "Com.qianfeng.zhouyi.drawerlayouttest.MainActivity" >
<framelayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>
<android.support.design.widget.navigationview
Android:layout_width= "Wrap_content"
android:layout_height= "Match_parent"
Android:layout_gravity= "left"
app:headerlayout= "@layout/layout_navhead"
app:menu= "@menu/mymenu"
Android:id= "@+id/navtest"
/>
</android.support.v4.widget.DrawerLayout>
----------------------------------------------------------------------------
Drawlayout only needs to configure the Layout_gravity property to "left" or "right" to automatically build the drawer to the ieft or the side, or two to configure
Headerlayout is to add a head layout to the navigation bar.
menu is the selection entry for the corresponding menu item.
--------------------------------------The response operation of the Navigationview--------------------------------------------
To set the Navigationview menu response:
Set the navigation bar Navigationview Click event Navigationview mnavigationview = (navigationview) Findviewbyid (r.id. Navigation_view); Mnavigationview.setnavigationitemselectedlistener (new Navigationview.onnavigationitemselectedlistener () { @Override public boolean onnavigationitemselected ( MenuItem MenuItem) { switch (Menuitem.getitemid ()) { //Event action ... } Menuitem.setchecked (TRUE);//Click to set it to the selected state mdrawerlayout.closedrawers ();//close drawer return true; });
Drawer implementation--