Android--slidingmenu Study Summary

Source: Internet
Author: User

Source

Slidingmenu is a relatively fire open source repository on GitHub. Very powerful, not only but simple settings to achieve the two-side sliding menu, but also to set the menu of shadow, gradient, scrub mode and so on.

:Https://github.com/jfeinstein10/SlidingMenu


How to use

To achieve the Slidingmenu effect, you first need to import it as a libary into your project.

Note : The Slidingmenu_library class library itself comes with a Android-support-v4.jar file, and our own project typically carries this file, assuming that the SHA-1 value of the two files is different and may appear

The exception for the class could not be found. My practice is to remove the Android-support-v4.jar from my project.




API Demo 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 Setbehindcontentview (r.layout.menu_frame);//Get the pull-down 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 content Display page corresponding DP size slidingmenu.setbehindoffsetres (R.DIMEN.SLIDINGMENU_OFFSET);////set the DP size of the left side drop column// Slidingmenu.setbehindwidtHRes (140);//Note that the unit of 140 is pixels/* * slidingmenu.left * slidingmenu.right * slidingmenu.left_right */// Set the position of the Slidingmenu.setmode (slidingmenu.left);//For the sidebar and right side content page area (vertical bar) 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: 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&LT 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;}}


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvd3vzzxl1a3vp/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">



Android--slidingmenu Study Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.