Slidingmenu side-slip menu is a relatively new setting interface or configuration interface effect, in the main interface left or right slide appear to set the interface effect, can easily do a variety of operations. Many good apps use this interface, like Facebook, Renren, Everynote, Google +, NetEase news, daily newspapers, Youdao Cloud notes, and more.
This interaction is now becoming more and more popular, although this interaction can be done by customizing the components, but it is easier to use a third-party open Source Library. Address: Https://github.com/jfeinstein10/SlidingMenu.git
Slide-Slip Menu Implementation principle:
There are two parts to the layout of an activity, one is the layout of the menu, and the other is the layout of the content. Two layouts are arranged horizontally, menu layout is left, content layout is right. When initialized, the menu layout is shifted to the left so that it can be completely hidden so that the content layout is fully visible in the activity. You can then change the left offset of the menu layout by listening to the finger swipe events to control the display and hiding of the menu layout.
Instance:
Operating effect:
To be able to achieve the Slidingmenu effect, you first have to import it as a libary into your project, the directory structure is as follows:
Code Listing:
Main interface Content layout: Activity_main.xml
<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 " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <textview android:layout_width=" wrap_content " android:layout_height=" Wrap_ Content " android:text=" @string/hello_world "/></relativelayout>
Slide-off menu layout: slidingmenu.xml
<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 " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <textview android:layout_width=" wrap_content " android:layout_height=" Wrap_ Content " android:text=" Sliding menu Layout "/></relativelayout>
Size resource file: Dimens.xml
<resources> <!--Default screen margins, per the Android Design Guidelines- <dimen name= " Activity_horizontal_margin ">16dp</dimen> <dimen name=" Activity_vertical_margin ">16dp</ dimen> <dimen name= "Slidingmenu_offset" >150dp</dimen> <dimen name= "Shadow_width" > 15dp</dimen></resources>
Shadow.xml Resources This resource file is a graphic used to achieve shadow effects, using a gradient drawing effect.
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <gradient android:endcolor= "#33000000" android:centercolor= "#11000000" android: Startcolor= "#00000000"/></shape>
Java source code file: Mainactivity.java
Package Com.rainsong.slidingmenudemo;import Android.os.bundle;import Android.app.activity;import android.view.Menu Import Com.jeremyfeinstein.slidingmenu.lib.slidingmenu;public class Mainactivity extends Activity {@Override prote CTED void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Instantiate a sliding Menu object slidingmenu menu = new Slidingmenu (this); Set to left slide menu Menu.setmode (slidingmenu.left); Set the touch screen mode menu.settouchmodeabove (Slidingmenu.touchmode_fullscreen); Sets the width of the sliding shadow Menu.setshadowwidthres (r.dimen.shadow_width); Sets the image resource for sliding shadow menu.setshadowdrawable (R.drawable.shadow); Sets the remaining width of the main page when the Slide menu is menu.setbehindoffsetres (R.dimen.slidingmenu_offset); Sets the value of the Fade Out Effect Menu.setfadedegree (0.35f); Attached to the activity menu.attachtoactivity (this, slidingmenu.sliding_content); Set the layout of the slide menu Menu.setmENU (r.layout.slidingmenu); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio n Bar if it is present. Getmenuinflater (). Inflate (R.menu.main, menu); return true; }}
Android UI Slidingmenu Sideways Menu