Summary of the implementation of sliding interface in Slidingmenu Open source project

Source: Internet
Author: User

First


What you need to prepare is to download actionbarsherlock-master.zip, and slidingmenu-master.zip These two open source files on GitHub First, then unpack the two packages, The library file inside the Slidingmenu is imported into a project in eclipse (where there is no emphasis on the import of a androidproject), and The Actionbarsherlock file inside the Actionbarsherlock is imported into eclipse.

After importing, it is necessary to set the library as a library so that it can be called later in other project. Detailed operations such as the following:

1. Select the libraryproject,alt+enter that you just imported


< /span> Click to select Android, then add the actionbarsherlock file (remember ). Then tick the islibrary above; the goal of this step is to have our library (the project Slidingmenu just imported) correlate actionbarsherlock project, Because it uses something actionbarsherlock.

2. Assume that after the first step of some students will find that may be error, this is due to the library Libs file in the package Android-support-v4.jar and actionbarsherlock differences, of course, due to the library reference Actionbarsherlock inside the content. So we can delete the Android-support-v4.jar inside the library under the Libs , and we can


3. The next step is to change the Slidingfragmentactivity.java in the library to allow it to inherit sherlockfragmentactivity.

4. Finish the above is your own new project to practice proof. I started with the Slidingmenu inside the example after the import, execution perfect, no flaws. And then you want to build a new one, and you get a lot of trouble.

< Span style= "font-size:18px" > < /span> first is the need to put their own new project inside the Libs under the jar to delete, a part of the students are good, but my bad luck, has been R.java file can not find. Look at the bottom of the error message, are in the actionbarsherlock inside the default some information,

Later found a half-day find I need to change the new project inside the Androidmainfest.xml file in the theme, changed to Android:theme= "@style /theme.sherlock" > Again, I have to thank the classmate called "Mind Dust" to help me.

< Span style= "font-size:18px" > < /span> just still have a problem, r file still can't find, reason this is clear, because I use the amount of Eclipse version number may be too high. The new project in it itself will rely on another package, which is the reason I create a new project myself to come out a package, and then the lock depends on the package has a lot of things and the library is conflicting, and some have been defined repeatedly, so I decisively delete this package, Then continue to see where the error, find the place to continue to delete the error, delete and then the mainactivity inherited class changed to the most primitive activity, will be good. Suppose you find a menu-related


The next step is to summarize some of the properties of Slidingmenu

Slidingmenu frequently uses attribute descriptions:
Menu.setmode (slidingmenu.left);//Set Left slide menu
Menu.settouchmodeabove (Slidingmenu.touchmode_fullscreen);//Set the sliding screen range, which can be slid across the full-screen area
Menu.setshadowdrawable (R.drawable.shadow);//Set Shadow Picture
Menu.setshadowwidthres (r.dimen.shadow_width);//Set the width of the shadow picture
Menu.setbehindoffsetres (R.dimen.slidingmenu_offset); the remaining width displayed on the main page when//slidingmenu
Menu.setbehindwidth (400);//Set the width of the Slidingmenu menu
Menu.setfadedegree (0.35f); degree of gradient when//slidingmenu sliding
Menu.attachtoactivity (this, slidingmenu.sliding_content);//enable the Slidingmenu to be attached to the activity
Menu.setmenu (r.layout.menu_layout);//Set Menu layout file
Menu.toggle ();//dynamically infer that you are actively shutting down or turning on slidingmenu
Menu.showmenu ();//Display Slidingmenu
Menu.showcontent ();//display content
Menu.setonopenlistener (Onopenlistener);//Monitor Slidingmenu Open
On the close menu there are two listeners, simply speaking, for the menu close event. One is when, one is after
Menu. Onclosedlistener (Onclosedlistener);//monitor Slidingmenu Shutdown Event
Menu. Onclosedlistener (Onclosedlistener);//monitor Slidingmenu post-shutdown event

Left and right can be slidingmenu menu only need to set
Menu.setmode (slidingmenu.left_right); property, and then set the layout file for the right side menu
Menu.setsecondaryshadowdrawable (r.drawable.shadowright);//Shadow picture on right side menu

Setting the Slidingmenu property
SM = Getslidingmenu ();
Let's say that the left side menu is only displayed, right, and left, support is Left_right
Sm.setmode (slidingmenu.left_right);//Set menu sliding mode, whether the menu is on the left or right side, or both sides have
Sm.setshadowdrawable (R.drawable.shadow);//Set the Shadow's picture resource
Sm.setshadowwidthres (r.dimen.shadow_width);//Set the width of the shadow picture
Sm.setbehindwidth (200);//Setting the width of the menu
Sm.setbehindoffsetres (R.dimen.slidingmenu_offset); the remaining width displayed on the main page when//slidingmenu
Sm.settouchmodeabove (Slidingmenu.touchmode_fullscreen);//Set the area of the slide

Support the right side to underline the menu:
Slidingmenu can support both sides of the menu at the same time. No conflict, and the animation is beautiful, good experience.
Sm.setsecondarymenu (r.layout.menu_frame2);//Set Right side menu
Sm.setsecondaryshadowdrawable (r.drawable.shadowright);//Set a picture resource for the right side menu shadow
Right side Slidingmenu's fragment
Getsupportfragmentmanager (). BeginTransaction (). Replace (r.id.menu_frame2, New Samplelistfragment ()). commit ();

Slidingmenu = Getslidingmenu ();
Whether the setting is left or right, or whether you can slide around
Slidingmenu.setmode (Slidingmenu.left_right);
Set Shadow Width
Slidingmenu.setshadowwidth (Getwindowmanager (). Getdefaultdisplay (). GetWidth ()/40);
Set left menu Shadow picture
Slidingmenu.setshadowdrawable (R.drawable.shadow);
Set Right menu shadow picture
Slidingmenu.setsecondaryshadowdrawable (R.drawable.right_shadow);
Set the ratio of the menu to the screen
Slidingmenu.setbehindoffset (Getwindowmanager (). Getdefaultdisplay (). GetWidth ()/5);
Sets whether the menu fades when sliding
Slidingmenu.setfadeenabled (TRUE);
Set the scale of the fade
Slidingmenu.setfadedegree (0.4f);
Set the drag effect when sliding
Slidingmenu.setbehindscrollscale (0);
To set the menu to slide, touch the range of the screen
Slidingmenu.settouchmodeabove (Slidingmenu.touchmode_fullscreen);

Attach a simple paragraph of your own writing

Slidingmenu menu = new Slidingmenu (this); Menu.setmode (Slidingmenu.left); 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); Menu.setmenu (r.layout.left_drawer_fragment); Menu.setonopenedlistener (New Slidingmenu.onopenedlistener () {@Overridepublic void onopened () {//TODO auto-generated Method stub}}); Init ();}

public void init () {//layoutinflater inflater = Layoutinflater.from ();//setvisible (r.layout.left_drawer_fragment); Mlinearlayout = (linearlayout) Findviewbyid (r.id.textlayout); mTextView1 = (TextView) Findviewbyid (R.ID.TEXTVIEW1); MTextView2 = (TextView) Findviewbyid (r.id.textview2); mTextView3 = (TextView) Findviewbyid (R.ID.TEXTVIEW3); mTextView4 = (TextView) Findviewbyid (R.ID.TEXTVIEW4); mTextView5 = (TextView) Findviewbyid (r.id.textview5); mTextView6 = (TextView ) Findviewbyid (R.ID.TEXTVIEW6); Mtextview1.setonclicklistener (this); Mtextview2.setonclicklistener (this); Mtextview3.setonclicklistener (This), Mtextview4.setonclicklistener (This), Mtextview5.setonclicklistener (this); Mtextview6.setonclicklistener (this);} @Overridepublic void OnClick (view view) {//TODO auto-generated method Stubswitch (View.getid ()) {case R.id.textview1:mla Yout.setbackgroundcolor (Color.Blue); Break;case R.id.textview2:mlayout.setbackgroundcolor (Color.GREEN); break; Case R.id.textview3:case R.id.textview4:case R.ID.TEXTVIEW5:CASe r.id.textview6:mlayout.setbackgroundcolor (color.white); break;}} 

The only image you can use is a substitute for it.

Summary of the implementation of sliding interface in Slidingmenu Open source project

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.