Jeff Lee blog:http://www.cnblogs.com/alandre/(Mud brick Carpenter), retain the URL when reproduced! Thanks
:
Resources to the top of the first page Add group can.
I. Slidingmenu INTRODUCTION
Github:https://github.com/jfeinstein10/slidingmenu
On the official website, the above description is translated:
Slidingmenu is an open source Android library that makes it easy for developers to develop a sliding menu app (like Google+,youtube,facebook). By introducing the license code for this open source library, you can easily use the app that you want to swipe the menu for free. As shown in the following:
Two. Official Small example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public class Slidingexample extends Activity { @Override public void OnCreate (Bundle savedinstancestate) { super.oncreate ( Savedinstancestate); settitle (R.string.attach); //Set the content view setcontentview (r.layout.content); //Configure the Slidingmenu slidingmenu menu = new Slidingmenu (this); menu.setmode (Slidingmenu.left); menu.settouchmodeabove (Slidingmenu.touchmode_fullscreen); menu.setshadowwidthres (R.dimen.shadow_width); menu.setshadowdrawable (R.drawAble.shadow); menu.setbehindoffsetres (R.dimen.slidingmenu_offset); menu.setfadedegree (0.35f); menu.attachtoactivity (this, slidingmenu.sliding_content); menu.setmenu (R.layout.menu); } } |
Naturally you can also define a slidingmenu with XML
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<com.jeremyfeinstein.slidingmenu.lib.slidingmenu xmlns:sliding= "/http Schemas.android.com/apk/res-auto " android:id=" @+id/slidingmenulayout " android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" sliding:viewabove= "@layout/your_above_view" sliding:viewbehind= "@ Layout/your_behind_behind " sliding:touchmodeabove=" Margin|fullscreen " sliding:behindoffset= "@dimen/your_offset" sliding:behindwidth= "@dimen/your_width" sliding:behindscrollscale= "@dimen/your_scale" sliding: shadowdrawable= "@drawable/your_shadow" sliding:shadowwidth= "@dimen/your_shadow_width" sliding:fadeenabled= "True|false" sliding:fadedegree= "float" slidinG:selectorenabled= "True|false" sliding:selectordrawable= "@drawable/your_selector"/> |
The official documents are translated as follows:
- Viewabove-Layout reference above the menu
- Viewbehind-Layout Reference under Menu
- Touchmodeabove-refers to that part of the screen touch rear view display
- Behindoffset-How much the body displays (per pixel) when the menu is displayed
- Behindwidth-The menu shows the width of the body display. Default Full Screen
- Behindscrollscale-Scrolling settings for menu display
- Shadowdrawable-scrolling Shadow Settings
- Shadowwidth-width of the scrolling shadow
- Fadeenabled-whether the menu is gradient when sliding
- Fadedegree-degree of gradient when sliding
Three. Implement the sliding menu
Main structure: Mainact as the main entrance, then each fragment to achieve their respective content action.
Mainact.java
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
public class Mainact extends Fragmentactivity { private slidingmenu menu; & nbsp; @Override public void OnCreate (Bundle Savedinstancestate) { super.oncreate (savedInstanceState); setcontentview (R.layout.slidingmenu_main); menu = new Slidingmenu (this); menu.settouchmodeabove (Slidingmenu.touchmode_fullscreen); menu.setshadowwidthres (R.dimen.slidingmenu_shadow_width); menu.setshadowdrawable (R.drawable.slidingmenu_shadow); menu.setbehindoffsetres (R.dimen.slidingmenu_offset); &nBsp; displaymetrics dm = new Displaymetrics (); getwindowmanager (). Getdefaultdisplay (). GetMetrics (DM); menu.setfadedegree (0.35f); menu.setbehindoffset (dm.widthpixels*50/100); menu.attachtoactivity (this, slidingmenu.sliding_content); menu.setmode (slidingmenu.left_right);//Here the mode is set to the left and right menu, Right menu is displayed, left side menu is displayed, Left_righ menu is displayed menu.setcontent ( R.layout.slidingmenu_content); menu.setmenu (R.layout.slidingmenu_menu); Menu.setsecondarymenu (R.layout.slidiNgmenu_menu_2); menu.setsecondaryshadowdrawable (R.drawable.slidingmenu_shadow_ 2); Getsupportfragmentmanager () . BeginTransaction () .replace ( R.id.slidingmenu_content, new Mainfragment (menu)) .commit ();//Set Home page content getsupportfragmentmanager () .begintransaction () . Replace (R.id.slidingmenu_menu, New Mainleftfragment ()) .Commit ();//Set left menu contents getsupportfragmentmanager () .begintransaction () .replace ( R.id.slidingmenu_menu_2, new Mainrightfragment (menu)) .commit ();//Set Right menu contents } } |
Summary: The use of simple is difficult
Android UI (iii) SLIDINGMENU implementation Sliding menu (detail official)