Android is a lot of products (such as 360 mobile phone assistants, netease menu ...). ) all use the Display form of sideslip menu, using this kind of display form
1, can put more of the content of the presentation are stored in the menu
2, the design can also reflect the visual effect
Now this kind of interaction is becoming more and more popular, although this kind of interaction can be realized by customizing the component, but it is simpler to use the tripartite open Source Library.
Slidingmenu: Slidingmenu is a relatively new setting interface or configuration interface effect, in the main interface left or right sliding appears to set the interface, can easily carry out a variety of operations. At present, a large number of applications are using this effect.
Address: Https://github.com/jfeinstein10/SlidingMenu.git
Now create a new Android project Slidingmenudemo,
Activity_main:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
xmlns:tools= "http:// Schemas.android.com/tools "
android:layout_width=" match_parent "
android:layout_height=" Match_parent "
>
<textview
android:layout_width= "fill_parent"
android:layout_height= "Fill_parent"
android:text= "Content"
android:textsize= "24sp"
android:textcolor= "#000"
android:gravity= "center"
/>
</RelativeLayout>
Menu Activity_menu on the left:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <textview android:layout_width= "Fill_" Parent "android:layout_height=" 40DP "android:gravity=" center "android:text=" Sports "android:textsize=" 16sp "Android : textcolor= "#000"/> <textview android:layout_width= "fill_parent" android:layout_height= "40DP" android:gr avity= "center" android:text= "Entertainment" android:textsize= "16sp" android:textcolor= "#000"/> <textview Android : layout_width= "fill_parent" android:layout_height= "40DP" android:gravity= "center" android:text= "Finance" Android:textS Ize= "16sp" android:textcolor= "#000"/> <textview android:layout_width= "Fill_parent" android:layout_height = "40DP" android:gravity= "center" android:text= "technology" android:textsize= "16SP" android:textcolor= "#000"/> &L T TextView android:layout_width= "FIll_parent "android:layout_height=" 40DP "android:gravity=" center "android:text=" Hangzhou "android:textsize=" 16sp "and Roid:textcolor= "#000"/> </LinearLayout>
Mainactivity.java:
Package Com.example.slidingmenudemo;
Import Com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
Import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
Import Android.os.Bundle;
Import Android.view.Window;
Import android.app.Activity;
public class Mainactivity extends Slidingfragmentactivity {
private slidingmenu sm;
@Override public
void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Requestwindowfeature (window.feature_no_title);
1 Set the Slide menu next to the page
Setbehindcontentview (r.layout.activity_menu);
Setcontentview (r.layout.activity_main);
2 Get sliding menu
sm = Getslidingmenu ();
3 Set left sliding menu
sm.setmode (slidingmenu.left);
4 Set the sliding menu out, the content page remaining width
sm.setbehindoffsetres (r.dimen.slidingmenu_offset);
Sm.settouchmodeabove (slidingmenu.touchmode_fullscreen);
6 Setting Shadow
sm.setshadowdrawable (R.drawable.shadow);
Sm.setshadowwidthres (r.dimen.shadow_width);
}
Note that activity must inherit slidingfragmentactivity.
Now look at Slidingmenu some properties:
Menu.setmode (slidingmenu.left);//Set Left sliding menu
menu.settouchmodeabove (slidingmenu.touchmode_fullscreen); Sets the screen range for sliding, which is set to slide
menu.setshadowdrawable (R.drawable.shadow) in a full-screen area;//Set Shadow Picture
Menu.setshadowwidthres ( R.dimen.shadow_width);//Set the width of the shadow picture
menu.setbehindoffsetres (r.dimen.slidingmenu_offset); Slidingmenu the remaining width of the main page displayed
menu.setbehindwidth (400);//Set the width of the Slidingmenu menu
menu.setfadedegree (0.35f); Slidingmenu when sliding
menu.attachtoactivity (this, slidingmenu.sliding_content);//make slidingmenu attached to activity
Menu.setmenu (r.layout.menu_layout);//Set menu layout file
menu.toggle ()//dynamic judgment automatically closes or opens Slidingmenu
Menu.showmenu ()//Display Slidingmenu
menu.showcontent ()//display content
Can be left or right to draw the Slidingmenu menu only need to set
Menu.setmode (slidingmenu.left_right); property, and then set the layout file menu.setsecondaryshadowdrawable for the right menu
( R.drawable.shadowright);//Shadow Picture of right menu
Setting the Slidingmenu Property
SM = Getslidingmenu ();
If only the left menu is displayed, the right side will be supported on Left_right Sm.setmode (slidingmenu.left_right), or the menu will
appear on the left or right, Or the left and right sides have
sm.setshadowdrawable (R.drawable.shadow);//Set the shadow of the picture resource
sm.setshadowwidthres (r.dimen.shadow_width //sets the width of the shadow picture
//sm.setbehindwidth (200);//Set the width
sm.setbehindoffsetres (r.dimen.slidingmenu_offset) of the menu; Slidingmenu the remaining width of the main page displayed
sm.settouchmodeabove (slidingmenu.touchmode_fullscreen);//Set Sliding area
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.