Inspired by Slidingmenu Android adds Drawerlayout to implement the swipe menu
Drawerlayout is inherited from the ViewGroup, where you can place the child view. Drawerlayout the main content area and menu area
Use the following method
1. Same as the normal linearlayout
<android. Support. V4. Widgets. DrawerlayoutXmlns:android="Http://schemas.android.com/apk/res/android"Android:id="@+id/drawer_layout"Android:layout_width="Match_parent"android:layout_height="Match_parent"> <framelayout android:id="@+id/content_frame"Android:layout_width="Match_parent"android:layout_height="Match_parent"/> <listview android:id="@+id/left_drawer"Android:layout_width="240DP"android:layout_height="Match_parent"android:layout_gravity="Start"Android:choicemode="Singlechoice"android:layout_gravity="left"Android:divider="@android: Color/transparent"android:dividerheight="0DP"Android:background="#111"/></android. Support. V4. Widgets. Drawerlayout>
Fragment is the main content, not necessarily with fragment, any view can be, the ListView is a menu, the same as any view can be.
Note: (1) The main content layout should be placed in front of the menu layout to help Drawerlayout to identify what the menu layout is and what is the content layout
(2) android:choicemode= "Singlechoice" is a statement which is the menu layout
Android:layout_gravity= "Left" is a side-by-side slide, this value can be changed
2 the display and the hidden state of the menu have a corresponding listener interface call, you can add the logic you want to implement
mdrawertoggle = new Actionbardrawertoggle (this , Mdrawerlayout, R.drawable.ic_drawer, R.string . Drawer_open, R.string . Drawer_close) {public void ondrawerclosed (View view) {} public void ondraweropened (View drawerview) {}}; Mdrawerlayout.setdrawerlistener (mdrawertoggle);
3. Automatic control of menu opening and closing in code
The Drawerlayout.closedrawer method is used to hide the side menu, and the Drawerlayout.opendrawer method is used to expand the side menu
4, sometimes we just want to click on a button to display the menu and do not want to let a swipe to appear menu, then this time will be blocked off the sliding function
Mdrawer_layout.setdrawerlockmode (drawerlayout.lock_mode_locked_closed); Turn off gesture swipe
Mdrawer_layout.setdrawerlockmode (drawerlayout.lock_mode_unlocked); Open gesture Swipe
Android comes with drawerlayout sliding menu