I. Introduction of Slidingmenu
I believe that everyone is not unfamiliar with the slidingmenu, it is a relatively new set interface or configuration interface effect, in the main interface left or right slide appear to set the interface effect, can easily carry out a variety of operations. Many good apps use this interface, like Facebook, Renren, Everynote, Google +, and more. As shown in the following:
Because the effect is really relatively new, so in a lot of application development to achieve this effect, the solution is different. Many comparisons are made later
Now, or the open source project on GitHub, Slidingmenu offers the best possible implementation: flexible customization, a variety of shades and gradients, and animations that have a good sliding effect. But this is an open source library, not a complete project, to introduce it as a libary into your own project, simple configuration can achieve slidingmenu effect.
Second, the use of Slidingmenu
Slidingmenu_library:https://github.com/yexiaochao/slidingmenu_library
To be able to achieve the Slidingmenu effect, you first have to import it as a libary into your project
1. After the download is complete, import this project into the Eclipse development environment
2. After importing the project, then create a new Android project and import the slidingmenu_library into the new Android project with the following steps:
<1> Right click on the new Android project and click on the "Properties" option at the bottom.
<2> Click the "Android" option on the left and then click the "Add" button at the bottom right after clicking on the popup dialog box.
<3> Click the pop-up dialog to select the previously imported Slidingmenu_library project
<4> after selection;
<5> This shows that the import library has been successful, and after the successful import, a Slidingmenu_library.jar package will appear in the Android reference package;
Note: Here's a place to pay special attention, after the new Android project is created, the newer version of Eclipse will generate a Libs folder in the Android directory. Inside there will be a Android-support-v4.jar jar package, this jar must remember to delete, or run the program when there will be an exception, the hint is not found the class exception. The reason for the exception is because when you import the Slidingmenu_library class library, This class library itself contains the Android-support-v4.jar jar package, so when the runtime will be abnormal, the system does not know which path to call the next package, so the program crashes, the hint can not find the class.
Iii. Examples of Slidingmenu
1. Film (GIF image is larger, 3.6M)
2. Code explanation
1. Project Structure Chart
2. Content_frame.xml layout
<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/menu_frame " android:layout_width=" match_parent " android:layout_height=" Match_parent "/><!--defines a virtual view that makes it easy for fragment to replace the view to achieve the effect that fragment view content can display on the screen. -
3. Menu_frame.xml Layout
<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/menu_frame " android:layout_width=" match_parent " android:layout_height=" Match_parent "/><!--is used to store the view screen after the sliding menu is opened. -
4, List.xml
<?xml version= "1.0" encoding= "Utf-8"? ><listview xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @android: Id/list " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:paddingleft=" @dimen/list_padding " android:paddingright=" @dimen/list_padding "/ ><!--This list layout file will be used in listfragment. -
5, Row.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" 50DP " android:orientation=" Horizontal "> <imageview android:id=" @+id/row_icon " android:layout_width=" 50DP " android: layout_height= "50DP" android:padding= "10DP" android:src= "@drawable/ic_launcher"/> <textview android:id= "@+id/row_title" android:layout_width= "0DP" android:layout_height= "Match_parent" android:layout_weight= "1" android:gravity= "center_vertical" android:padding= "10DP " android:text= "Medium text" android:textappearance= "@android: Style/textappearance.medium"/></ linearlayout><!--for storing pictures and text in a list. -
6. Shadow.xml Resources
<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <gradient android:centercolor= "#11000000" android:endcolor= "#33000000" android: Startcolor= the "#00000000"/></shape><!--the graphic used to achieve the shadow effect, using a gradient drawing effect. -
7, Samplelistfragment class
Package Com.yanis.slidingmenu;import Android.content.context;import Android.os.bundle;import Android.support.v4.app.listfragment;import Android.view.layoutinflater;import Android.view.View;import Android.view.viewgroup;import Android.widget.arrayadapter;import Android.widget.imageview;import android.widget.textview;/** * Underline the menu bar-used to display the list in the interface. */public class Samplelistfragment extends Listfragment {public View Oncreateview (Layoutinflater Inflater, ViewGroup Co Ntainer, Bundle savedinstancestate) {return inflater.inflate (r.layout.list, NULL); } public void onactivitycreated (Bundle savedinstancestate) {super.onactivitycreated (savedinstancestate); Sampleadapter adapter = new Sampleadapter (getactivity ()); for (int i = 0; i < i++) {Adapter.add (New Sampleitem ("Sample List", Android. R.drawable.ic_menu_search)); } setlistadapter (adapter); } public class Sampleadapter extends Arrayadapter<sampleitem> {public Sampleadapter (context context) {Super (context, 0); Public View GetView (int position, View Convertview, ViewGroup parent) {if (Convertview = = null) { Convertview = Layoutinflater.from (GetContext ()). Inflate (R.layout.row, NULL); } ImageView icon = (ImageView) Convertview.findviewbyid (R.id.row_icon); Icon.setimageresource (GetItem (position). Iconres); TextView title = (TextView) Convertview.findviewbyid (r.id.row_title); Title.settext (GetItem (position). tag); return convertview; }} private class Sampleitem {public String tag; public int iconres; Public Sampleitem (String tag, int iconres) {This.tag = tag; This.iconres = Iconres; } }}
8,slidingmenuactivity_1, slidingmenuactivity_2 and other categories
These classes are settings for the properties of the Slidingmenu, and the following is a simple, detailed view of the source code.
Package Com.yanis.slidingmenu;import Android.os.bundle;import Android.support.v4.app.fragmentactivity;import com.jeremyfeinstein.slidingmenu.lib.slidingmenu;/** * * @author Yechao * @ explains a simple effect of placing a slide menu bar on the left */public class Slidingme Nuactivity_2 extends Fragmentactivity {private Slidingmenu menu; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Set the title Settitle ("Attach"); Initialize the sliding menu initslidingmenu (); }/** * Initialize sliding menu */private void Initslidingmenu () {//Set main interface view Setcontentview (r.layout.content _frame); Getsupportfragmentmanager (). BeginTransaction (). Replace (R.id.content_frame, New Samplelistfragment ()). Commi T (); Sets the value of the Sliding menu's Properties menu = new Slidingmenu (this); 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); Set the view interface of the sliding menu Menu.setmenu (r.layout.menu_frame); Getsupportfragmentmanager (). BeginTransaction (). Replace (R.id.menu_frame, New Samplelistfragment ()). Commit () ; } @Override public void onbackpressed () {//Click the back key to close the swipe menu if (menu.ismenushowing ()) {Menu.s Howcontent (); } else {super.onbackpressed (); } }}
Source code Address: Https://github.com/YeXiaoChao/Yc_ui_slidingmenu
This address: http://www.cnblogs.com/yc-755909659/p/4306938.html
SOURCE article:
http://blog.csdn.net/yangyu20121224/article/details/9255829
http://blog.csdn.net/yangyu20121224/article/details/9258275
Category: "Android Development" tab: "Android UI design and development"
"Android UI design and development" 9: Sliding menu bar (i) Use and examples of open source projects Slidingmenu-Go