Simple implementation of the Android slide menu (slidingmenu)

Source: Internet
Author: User

When I had not studied Android, I used a side-by-side menu app, when the first feeling was: Wow, this effect is good! Of course, now I have already learned Android, the effect of course also to make AH ~

Slidingmenu is a relatively new setup interface or the effect of the configuration interface (I think it is not new), 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 +, and more. Effects such as:

In fact, there are a lot of online writing slidingmenu use of the article. However, others are always others, the following to achieve it.

Slidingmenu is an open source repository on GitHub, so visit GitHub first.

Slidingmenu Address: Https://github.com/jfeinstein10/SlidingMenu

The interface after opening the URL is as follows:

Click "Download ZIP" in the bottom right corner of the interface to download the open Source Library.

It is important to note that just downloading the open source Library is not enough, and by reading the Web page, the Slidingmenu Open Source Library relies on another open source library Actionbarsherlock, so you also need to download the Open Source Library Actionbarsherlock.

Click "Actionbarsherlock" with hyperlinks in the interface to jump to the URL: http://actionbarsherlock.com/'s Web page with the following interface:

Click the red arrow in the graph to point to the "Zip" to download the required open Source Library Actionbarsherlock.

After downloading these two open source libraries are all compressed files, so you need to unzip:

OK, this is the end of the prep work.

Start knocking on the code ...

Now that you have added these two open source libraries to eclipse, you need to be careful about selecting the imported directories (because there are a lot of extracted files, not every one needs to be imported). Such as:

After successfully importing the Open Source Library, consider changing their names to "Slidingmenulibrary" and "Actionbarsherlock", respectively.

Now create a new Android project, select System for Android4.0, project named "Test_slidingmenu"

Next, add two open source libraries to your project. Click Project Project name, right click and select "Properties".

(In the red circle, add these two open source libraries)

At this point, you may receive the following error:

Don't panic, this error occurs because the Suppor-v4.jar package used in these two open source libraries is different from the version of the Suppor-v4.jar package in the project you just created.

Then copy the Suppor-v4.jar package from the project into these two open source libraries and replace the Suppor-v4.jar package in the two open source libraries. In this way, the three Suppor-v4.jar packages are the same.

The next thing that's left is the code problem.

The first is to create a new layout file named Slidingmenu.xml: (We have added a button to the slide-in menu)

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#ff999999"android:orientation= "vertical" >    <Com.jeremyfeinstein.slidingmenu.lib.SlidingMenuAndroid:id= "@+id/slidingmenu"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" >        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "00000"/>    </Com.jeremyfeinstein.slidingmenu.lib.SlidingMenu></LinearLayout>

Also, add a line of code to the Dimens.xml:

<name= "Slidingmenu_offset">200dp</dimen >

The effect of 200DP in this code is to set the width of the slide-out menu stretch.

Then there is the code in the activity:

(The code is relatively simple, directly on the code ha)

 Public classMainactivityextendsActivity {PrivateSlidingmenu Slidingmenu; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Slidingmenu=NewSlidingmenu ( This); Slidingmenu.setmode (slidingmenu.left);//left side of the slide menuSlidingmenu.setbehindoffsetres (R.dimen.slidingmenu_offset);//set the stretch width of the slide-by menuSlidingmenu.settouchmodeabove (Slidingmenu.touchmode_fullscreen);//Full Screen Touch effectiveSlidingmenu.attachtoactivity ( This, slidingmenu.sliding_content);//Attach to ActivitySlidingmenu.setmenu (R.layout.slidingmenu);//Setting the side- Slip Menu Interface} @Override Public BooleanOnKeyDown (intKeyCode, KeyEvent event) {        Switch(keycode) { CaseKeyEvent.KEYCODE_MENU:slidingmenu.toggle (true);//Set the Click menu button to animate the result.              Break; default:             Break; }        return Super. OnKeyDown (KeyCode, event); }}

Operating effects such as:

Demo Download: http://download.csdn.net/detail/af74776/8074319

Simple implementation of the Android slide menu (slidingmenu)

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.