Source
Slidingmenu is a relatively fire open source Library on GitHub, very powerful, not only simple settings for both sides of the sliding menu, you can also set the menu shadow, gradient, scrub mode and so on.
:Https://github.com/jfeinstein10/SlidingMenu
How to use
To be able to achieve the Slidingmenu effect, you first have to import it as a libary into your project.
Note : The Slidingmenu_library class library itself has the Android-support-v4.jar file, and our own project usually carries this file, if the SHA-1 value of two files is different, it may appear
I can't find the exception to the class, I'm doing it by removing the Android-support-v4.jar from my project.
API Sample Code
Package Com.example.slidingmenu_left;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.view.window;import Com.example.slidingmenu_left.fragment.menufragment;import Com.jeremyfeinstein.slidingmenu.lib.slidingmenu;import Com.jeremyfeinstein.slidingmenu.lib.app.slidingfragmentactivity;public class Mainactivity extends slidingfragmentactivity {private Slidingmenu slidingmenu; @Overridepublic void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Requestwindowfeature (window.feature_no_title);//content page Layout Setcontentview ( r.layout.content)///Set the side Pull entry layout setbehindcontentview (r.layout.menu_frame);//Get the side pull Column object slidingmenu = Getslidingmenu (); * * slidingmenu.touchmode_fullscreen Full Screen Touch drag effective * slidingmenu.touchmode_margin drag edge Effective * slidingmenu.touchmode_none Full screen does not respond to touch drag event */slidingmenu.settouchmodeabove (slidingmenu.touchmode_margin);// Set the DP size Slidingmenu.setbehindoffsetres (R.DIMEN.SLIDINGMENU_OFFSET) for the Content Display page,////set the DP size of the left side pull column// Slidingmenu.setbehindwidtHRes (140);//Note that the unit of 140 is pixels/* * slidingmenu.left * slidingmenu.right * slidingmenu.left_right */// Set the position of the side pull column slidingmenu.setmode (slidingmenu.left);//For the side-pull column and the right side of the content page area (vertical) slidingmenu.setshadowdrawable ( R.drawable.shadow);//Set (vertical bar) width slidingmenu.setshadowwidthres (r.dimen.shadow_width);//fragment to replace node in layout fragment fragment = new Menufragment (); Getsupportfragmentmanager (). BeginTransaction ()//Open transaction. Replace (R.id.menu, fragment, " Menu ")//replace the layout. commit ();//COMMIT TRANSACTION}/** * Current class to replace the current display interface operation * @author Wuseyukui * * @param fragment */public void Switchfrag ment (Fragment Fragment) {if (Fragment! = null) {Getsupportfragmentmanager (). BeginTransaction (). Replace (R.id.content_ Frame, fragment, "CONTENT"). commit (); Slidingmenu.toggle ();}}}
Package Com.example.slidingmenu_left.fragment;import Java.util.arraylist;import Java.util.list;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.util.log;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.arrayadapter;import Android.widget.listview;import Com.example.slidingmenu_left. Mainactivity;import Com.example.slidingmenu_left. R;public class Menufragment extends Fragment {private String tag = "Menufragment";p rivate View view;/** * Create Object */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); LOG.I (Tag, "=====oncreate");} /** * Similar to: Setcontentview * Set layout */@Overridepublic View Oncreateview (layoutinflater inflater, ViewGroup container,bundle SA Vedinstancestate) {LOG.I (tag, "=====oncreateview"); view = View.inflate (Getactivity (), r.layout.list_view, NULL); return view;} /** * Data Fill operation */@Overridepublic void onactivitycreated (Bundle savedinstancestate) {super.onactivitycreated ( Savedinstancestate); LOG.I (Tag, "=====onactivitycreated"); ListView ListView = (ListView) View.findviewbyid (R.id.list_view); Listview.setadapter (New arrayadapter<string> (Getactivity (), Android. R.layout.simple_list_item_1, Android. R.id.text1, InitData ())); Listview.setonitemclicklistener (new Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> parent, View view,int position, long id) {Fragment Fragment = Null;switch (position) {CAs E 0:fragment = new Fragment1 (); Break;case 1:fragment = new Fragment2 (); Break;case 2:fragment = new Fragment3 (); break;case 3:fragment = new Fragment4 (); Break;case 4:fragment = new Fragment5 (); break;default:break;} Swithfragment (fragment);}});} private void Swithfragment (Fragment Fragment) {if (getactivity () instanceof mainactivity) {(mainactivity) getactivity ( ). Switchfragment (fragment);}} Private List<string> InitData () {ARRAYLIST< string> arrayList = new arraylist<string> () Arraylist.add ("Column 1"), Arraylist.add ("Column 2"), Arraylist.add ("Column 3" ); Arraylist.add ("Column 4"); Arraylist.add ("Column 5"); return arrayList;}}
:
Android--slidingmenu Study Summary