Effects such as the following:
Drawerlayout comes from the SUPPORT.V4 package, so do not consider compatibility issues. Second, such a layout is similar to rage's side-slip menu, but is much lighter than the side-slip menu. The following describes how such layouts are used.
1. Import the SUPPORT.V4 package in your project.
2. Edit a layout, the root node is android.support.v4.widget.DrawerLayout, this node only agree to have two child nodes, the first is the content of the future main page, the second node is the "drawer" content, is generally a ListView. Example:
<android.support.v4.widget.drawerlayout xmlns:android= "Http://schemas.android.com/apk/res/android" Android:id = "@+id/drawer_layout" android:layout_width= "match_parent" android:layout_height= "match_parent" > <LinearLay Out android:id= "@+id/content_frame" android:layout_width= "match_parent" android:layout_height= "Match_ Parent "android:orientation=" vertical "> <textview android:layout_width=" match_parent " android:layout_height= "wrap_content" android:text= "hahaha ha ha ha ha ha ha haha haha" android:textcolor= "#000 "Android:textsize=" 20sp "/> <button android:id=" @+id/but_open "Android:layo Ut_width= "Match_parent" android:layout_height= "wrap_content" android:text= "open drawer"/> </linea Rlayout> <!--Be sure to add layout_gravity= "Start"--<listview android:id= "@+id/left_drawer" Android Oid:layout_width= "240DP" android:layout_height= "Match_parent" android:layout_gravity= "Start" android:background= "#111" Androi D:choicemode= "Singlechoice" android:divider= "@android: Color/transparent" android:dividerheight= "0DP"/>&L T;/android.support.v4.widget.drawerlayout>
3. Write code to listen for related events:
Package Com.example.drawerlayoutdemo1;import Android.app.activity;import Android.os.bundle;import Android.support.v4.widget.drawerlayout;import Android.util.log;import Android.view.gravity;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.arrayadapter;import Android.widget.Button; Import Android.widget.listview;public class Mainactivity extends activity{protected static final String TAG = "Mainactivi Ty ";p rivate drawerlayout mdrawerlayout = null;private ListView LV = null;private Button but_open = null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); mdrawerlayout = (drawerlayout) Findviewbyid (r.id.drawer_layout); LV = (ListView) Findviewbyid (r.id.left_drawer) ; but_open = (Button) Findviewbyid (R.id.but_open); But_open.setonclicklistener (new Onclicklistener () {@Overridepublic void OnclIck (View v) {mdrawerlayout.opendrawer (gravity.left);}}); Lv.setadapter (New arrayadapter<string> (this,r.layout.test,r.id.tv_item,new string[]{"Entry 1", "Entry 2", "Entry 3"}); Mdrawerlayout.setdrawerlistener (New Drawerlayout.simpledrawerlistener () {@Overridepublic void ondrawerclosed (View Drawerview) {log.i (TAG, "drawer closed ..."); @Overridepublic void ondraweropened (View drawerview) {log.i (TAG, "drawer open ..."); @Overridepublic void Ondrawerslide (View drawerview, float slideoffset) {log.i (TAG, "drawer sliding ..."); @Overridepublic void ondrawerstatechanged (int newstate) {switch (newstate) {case DRAWERLAYOUT.STATE_DRAGGING:LOG.I ( Tag, "drag state"); Break;case drawerlayout.state_idle:log.i (tag, "compact State"); Break;case drawerlayout.state_settling:log.i ( TAG, "set state"); break;default:break;}}); Lv.setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> Parent, View view,int position, long ID) {switch (position) {case 0:LOG.I (tag, "Entry 1 is clicked"), Break;case 1:log.i (tag, " Entry 2 is clicked "); Break;case 2:log.i (TAG," Entry 3 is clicked "); break;}});}}
"Android Notes" drawer-style layout----drawerlayout