Recently, there is a project need to use the sidebar, and hope that the left and right sides can slide out of the side menu, in the online Search implementation method, found that the most use of the great God Jfeinstein10 Slidingmenu Library, address https://github.com/ Jfeinstein10/slidingmenu, by importing the open Source Library into Eclipse, and introducing it as a library into its own project, can be configured to achieve slidingmenu effect, there are many examples on the web, we can next research, Beginners can modify the example directly in the development of their own applications, of course, this is not rigorous.
This development does not take the above approach, but rather the Slidingmenu Open Source Library as a rack package, through the introduction of the jar package to develop the project, so that the sliding layout can be reflected in the form of controls, the use of relatively simple. The code for this development reference is http://download.csdn.net/download/woaixinxin123/5883503
Mainactivity.java
PackageCom.example.slidingmenudemo;ImportAndroid.os.Bundle;Importandroid.support.v4.app.FragmentActivity;ImportAndroid.util.DisplayMetrics;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;Importandroid.widget.RelativeLayout;ImportAndroid.widget.RelativeLayout.LayoutParams;ImportCom.slidingmenu.lib.SlidingMenu; Referenced Slidigmenu package Public classLeftandrightactivityextendsfragmentactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initview (); } Private voidInitview () {FinalSlidingmenu menu =NewSlidingmenu ( This); Button Button=NewButton ( This); Button.settext ("Left"); Button.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {menu.showmenu (); } }); Button Button2=NewButton ( This); Button2.settext ("Right"); Button2.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {menu.showsecondarymenu (); } }); Relativelayout View=NewRelativelayout ( This); Layoutparams LLP=Newlayoutparams (layoutparams.wrap_content, layoutparams.wrap_content); Llp.addrule (Relativelayout.align_parent_left, relativelayout.true); View.addview (Button, LLP); Layoutparams RLP=Newlayoutparams (layoutparams.wrap_content, layoutparams.wrap_content); Rlp.addrule (Relativelayout.align_parent_right, relativelayout.true); View.addview (Button2, RLP); Setcontentview (view); Displaymetrics Metric=NewDisplaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Metric); intwidth =Metric.widthpixels; intHeight =Metric.heightpixels; Menu.setmode (Slidingmenu.left_right); Menu.settouchmodeabove (Slidingmenu.touchmode_fullscreen); Menu.setshadowwidthres (R.dimen.shadow_width); Menu.setshadowdrawable (R.drawable.shadow); Menu.setbehindoffsetres (R.dimen.slidingmenu_offset); Menu.setbehindwidth (Width*2/3); Menu.setfadedegree (0.35f); Menu.attachtoactivity ( This, slidingmenu.sliding_content); Menu.setmenu (R.layout.left_menu_frame); Menu.setshadowdrawable (R.drawable.shadow); Getsupportfragmentmanager (). BeginTransaction (). replace (R.id.left_menu_frame,Newnavigationfragment ()). commit (); The left menu interface isNavigationfragment OK
Menu.setsecondarymenu (r.layout.right_menu_frame); Menu.setsecondaryshadowdrawable (R.drawable.shadow); Left and right side slide out the menu style can be written by their own fragment customization, no longer repeat }}
Android slidingmenu slide out side bar