Android ui-slidingmenu Slide Menu effect

Source: Internet
Author: User

Android ui-slidingmenu Slide Menu effect


This blog to share a good effect on the side of the Slide menu demo, to achieve the click on the left menu switch fragment.

The effect is as follows:



Main Activity code:

Package Com.infzm.slidingmenu.demo;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.widget.imageview;import Android.widget.textview;import com.infzm.slidingmenu.demo.fragment.LeftFragment; Import Com.infzm.slidingmenu.demo.fragment.todayfragment;import Com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; Import com.jeremyfeinstein.slidingmenu.lib.app.slidingfragmentactivity;/** * @date 2014/11/14 * @author Wuwenjie * @ Description Main interface */public class Mainactivity extends slidingfragmentactivity implementsonclicklistener {private ImageView topbutton;private Fragment mcontent;private TextView toptextview; @Overridepublic void OnCreate (Bundle Savedinstancestate) {requestwindowfeature (window.feature_no_title);//Untitled super.oncreate (SavedInstanceState); Setcontentview (R.layout.activity_main); Initslidingmenu (savedinstancestate); Topbutton = (ImageView) findViewById ( R.id.topbutton); tOpbutton.setonclicklistener (this); Toptextview = (TextView) Findviewbyid (R.ID.TOPTV);} /** * Initialize the sidebar */private void Initslidingmenu (Bundle savedinstancestate) {//If the saved state is not empty then get the previously saved fragment, Otherwise instantiate myfragmentif (savedinstancestate! = null) {mcontent = Getsupportfragmentmanager (). Getfragment ( Savedinstancestate, "Mcontent");} if (mcontent = = null) {mcontent = new todayfragment ();} Set left slide menu Setbehindcontentview (r.layout.menu_frame_left); Getsupportfragmentmanager (). BeginTransaction (). Replace (R.id.menu_frame, New Leftfragment ()). commit ();//Instantiate the Sliding menu object Slidingmenu sm = Getslidingmenu ();// Set the menu Sm.setmode (slidingmenu.left) that can slide left and right,//Set the width of the sliding shadow Sm.setshadowwidthres (r.dimen.shadow_width);// Sets the image resource for the Slide menu shadow sm.setshadowdrawable (null);//sets the width of the Sliding menu view sm.setbehindoffsetres (r.dimen.slidingmenu_offset);// Sets the value of the fade-in Fade effect Sm.setfadedegree (0.35f);//sets the mode of touch screen, which is set to full screen sm.settouchmodeabove (slidingmenu.touchmode_fullscreen);// Sets the zoom ratio Sm.setbehindscrollscale (0.0f) for the lower view when scrolling;} @Overrideprotected void Onsaveinstancestate (Bundle outState) {super.onsaveinstancestate (outstate); Getsupportfragmentmanager (). Putfragment (Outstate, "mContent", mcontent);} /** * Toggle Fragment * * @param fragment */public void Switchconent (fragment fragment, String title) {mcontent = Fragment;get Supportfragmentmanager (). BeginTransaction (). replace (R.id.content_frame, fragment). commit (); Getslidingmenu (). Showcontent (); Toptextview.settext (title);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {case r.id.topbutton:toggle (); break;default:break;}}}


Side bar Menu Fragment

Package Com.infzm.slidingmenu.demo.fragment;import Android.app.activity;import Android.os.bundle;import Android.support.v4.app.fragment;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.viewgroup;import com.infzm.slidingmenu.demo.MainActivity; Import com.infzm.slidingmenu.demo.r;/** * @date 2014/11/14 * @author Wuwenjie * @description Sidebar menu */public class Leftfrag ment extends Fragment implements onclicklistener{private view Todayview;private view Lastlistview;private view Discussview;private View Favoritesview;private View Commentsview;private view settingsview; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);} @Overridepublic void Onattach (activity activity) {Super.onattach (activity);} @Overridepublic View Oncreateview (Layoutinflater inflater, ViewGroup container,bundle savedinstancestate) {View view = Inflater.inflate (R.layout.layout_menu, null); Findviews (view); return view;}public void Findviews (view view) {Todayview = View.findviewbyid (r.id.tvtoday); Lastlistview = View.findviewbyid ( r.id.tvlastlist);d Iscussview = View.findviewbyid (r.id.tvdiscussmeeting); Favoritesview = View.findViewById ( r.id.tvmyfavorites); Commentsview = View.findviewbyid (r.id.tvmycomments); Settingsview = View.findViewById ( r.id.tvmysettings); Todayview.setonclicklistener (this), Lastlistview.setonclicklistener (this); Discussview.setonclicklistener (This), Favoritesview.setonclicklistener (this); Commentsview.setonclicklistener ( this); Settingsview.setonclicklistener (this);} @Overridepublic void Ondestroyview () {Super.ondestroyview ();} @Overridepublic void OnDestroy () {Super.ondestroy ();} @Overridepublic void OnClick (View v) {Fragment newcontent = null; String title = Null;switch (V.getid ()) {case R.id.tvtoday://Today newcontent = new Todayfragment (); title = GetString (R.strin G.today); break;case r.id.tvlastlist://list newcontent = new Lastlistfragment (); title = GetString (r.string.lastlist); Break;case r.id. Tvdiscussmeeting://discussion Rally newcontent = new Discussfragment (); title = GetString (r.string.discussmeetting); break;case R.id.tvmyfavorites://My collection newcontent = new Myfavoritesfragment (); title = GetString (r.string.myfavorities); break;case R.id.tvmycomments://my comments newcontent = new Mycommentsfragment (); title = GetString (r.string.mycomments); break;case R.id.tvmysettings://Set newcontent = new Mysettingsfragment (); title = GetString (r.string.settings); Break;default: break;} if (newcontent! = null) {switchfragment (newcontent, title);}} /** * Toggle Fragment * @param fragment */private void Switchfragment (fragment fragment, String title) {if (getactivity () = = Nu ll) {return;} if (getactivity () instanceof mainactivity) {mainactivity FCA = (mainactivity) getactivity (); Fca.switchconent (fragment, title);}}}

Above is the core code, the introduction of Slidingmenu Open Source Library.

demo:http://download.csdn.net/download/wwj_748/8184889


Android ui-slidingmenu Slide Menu effect

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.