In-depth introduction to SlidingMenu and slidingmenu

Source: Internet
Author: User

In-depth introduction to SlidingMenu and slidingmenu

If you want to directly view the source code, you can download it from my Github: https://github.com/zhanghuijun0/demo-for-android/tree/master/SlidingMenu

SlidingMenu is an open-source Android project on github that can be used to quickly integrate the Android slide menu effect. Slidingmenu can contain multiple components such as fragment viewpager listview;

:

SlidingMenu: https://github.com/jfeinstein10/SlidingMenu

Actionbarsherlock: https://github.com/JakeWharton/ActionBarSherlock/tree/master/actionbarsherlock

Note: SlidingMenu depends on another open-source project ActionBarSherlock. Therefore, you need to add ActionBarSherlock as the Library Project of SlidingMenu. Otherwise, an error occurs when the resource cannot be found.

The dependency is as follows: ExampleListActivity --> library --> actionbarsherlock

Common problems:

(1) After adding the dependency, "Jar mismatch!" is reported! Fix your dependencies "error because the android-support-v4.jar version does not match. (Solution: remove the dependent android-support-v4.jar, re-Add the new, of course, from one of the projects, to another project, the purpose is the android-support-v4.jar version to be the same as OK)

(2) An error still exists in the library: getSupportActionBar (). setDisplayHomeAsUpEnabled (true) cannot be found );

Solution: locate src in the Library, locate SlidingFragmentActivity. java, modify the parent class, and set:

public class SlidingFragmentActivity extends FragmentActivity 

To:

public class SlidingFragmentActivity extends SherlockFragmentActivity

Then, clean: actionbarsherlock, library, and ExampleListActivity by dependency.

So far, a simple Demo of SlidingMenu has been imported successfully. Now we can see the effect of SlidingMenu. If you feel the above steps are troublesome, you can directly download the configuration I have already configured: click to download [GitHub]

After the configuration is complete, we need to write some SlidingMenu demos by ourselves. First, we need to add a library for the newly created Project. The following shows a simple SlidingMenu code, only a few lines of code can achieve a simple SlidingMenu effect.

 1 // configure the SlidingMenu 2 SlidingMenu menu = new SlidingMenu(this); 3 menu.setMode(SlidingMenu.LEFT); 4 menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); 5 menu.setShadowWidthRes(R.dimen.shadow_width); 6 menu.setShadowDrawable(R.drawable.shadow); 7 menu.setBehindOffsetRes(R.dimen.slidingmenu_offset); 8 menu.setFadeDegree(0.35f); 9 menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);10 menu.setMenu(R.layout.slide_menu);

The above SlidingMenu may be a bit simple. Below are some of my summary of the SlidingMenu attribute, which may not be very complete. If you need to complete it, check the Demo provided by SlidingMenu on Github;

1 // configure the SlidingMenu 2 menu = new SlidingMenu (this); 3 4 menu. setMode (SlidingMenu. LEFT); // set the LEFT slide menu 5 6 // menu. setMode (SlidingMenu. LEFT_RIGHT); // properties, and then set the layout file of the right menu 7 // menu. setSecondaryMenu (R. layout. activity_main); 8 // menu. setSecondaryShadowDrawable (R. drawable. shadow); // The shadow image 9 10/** 11 * on the right menu sets the sliding area 12 */13 menu. setTouchModeAbove (sregistringmenu. TOUCHMODE_FULLSCREEN); // full screen can be 14 // menu. setTouchModeAbove (sregistringmenu. TOUCHMODE_MARGIN); // you can click 15. // menu. setTouchModeAbove (sregistringmenu. TOUCHMODE_NONE); // The activity interface cannot be 16 17 18/** 19 * shadow 20 */21 menu. setShadowWidth (200); // set the shadow width to 22 menu. setShadowWidthRes (R. dimen. shadow_width); // set the width of the Shadow image to 23 menus. setShadowDrawable (R. drawable. shadow); // set the shadow image 24 25/** 26 * fade in and out 27 */28 menu. setFadeEnabled (true); // whether to fade in and out 29 menus. setFadeDegree (0.35f); // set the ratio of Fade-in and fade-out to 30 31. setBehindScrollScale (0.2f); // set the drag and drop effect 32 menus during sliding. setBehindWidth (400); // set the width of SlidingMenu to 33 menus. setBehindOffsetRes (R. dimen. slidingmenu_offset); // The remaining width 34 35 menu displayed on the home page when SlidingMenu is selected. attachToActivity (this, SlidingMenu. SLIDING_CONTENT); // append SlidingMenu to 36 menus on Activity. setMenu (R. layout. slide_menu); // set the layout file of menu 37 38 CanvasTransformer mTransformer = new CanvasTransformer () {39 @ Override40 public void transformCanvas (Canvas canvas, float percentOpen) {41 float scale = (float) (percentOpen * 0.25 + 0.75); 42 canvas. scale (scale, scale, canvas. getWidth ()/2,43 canvas. getHeight ()/2); 44} 45}; 46 menu. setBehindCanvasTransformer (mTransformer); // Custom Animation

Other attributes of SlidingMenu are well summarized by others. I will not repeat them here. If necessary, refer to the following address.

AndroidUI -- SlidingMenu example: http://www.cnblogs.com/zhjsll/p/3704552.html

[Android] SlidingMenu attribute details: http://www.cnblogs.com/SharkBin/p/3665548.html

Android slidingmenu detailed optimization side slide: http://blog.csdn.net/aaawqqq/article/details/44121577

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.