Simple implementation of the Android slide menu (slidingmenu) II

Source: Internet
Author: User

In the previous blog post, it was simple to implement the slide-off menu, the code is simple, just a few lines of code.

This article still tells the side-by-side menu, and unlike the previous article, this article uses a different code approach to implement the slide-by menu.

In the previous article, we have used the Slidingmenu construction method to set the side-by-side menu directly in the activity, which is replaced by the activity inheritance slidingactivity to achieve the slide.

The code is as follows:

 Public class extends Slidingactivity

Override the OnCreate () method:

@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Setbehindcontentview (r.layout.slidingmenu);//Set the slide -by layoutSlidingmenu menu = Getslidingmenu ();//Get SlidingmenuMenu.setmode (Slidingmenu.left); //Setting the mode of the touch screenMenu.settouchmodeabove (Slidingmenu.touchmode_fullscreen); //set the width of the Slide menu viewmenu.setbehindoffsetres (R.dimen.slidingmenu_offset); //set the value of the fade-in fade-out effectMenu.setfadedegree (0.35f); }

The rest follow the same blog post.

The results of the operation are as follows:

The effect is exactly the same as in the previous blog post.

Another way is to use Slidingmenu as a general control and use it directly in the XML layout.

Here's how:

Activity_main.xml:

<?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:orientation= "vertical" >    <Com.jeremyfeinstein.slidingmenu.lib.SlidingMenuxmlns:sliding= "Http://schemas.android.com/apk/res-auto"Android:id= "@+id/slidingmenulayout"Android:layout_width= "120DP"Android:layout_height= "170DP"Android:background= "#ffffffff"Sliding:behindoffset= "0DP"Sliding:behindscrollscale= "1"Sliding:fadedegree= "0.3"sliding:fadeenabled= "true"Sliding:touchmodeabove= "fullscreen"Sliding:viewabove= "@layout/pic" >    </Com.jeremyfeinstein.slidingmenu.lib.SlidingMenu></LinearLayout>

Additional layout files are required:

Pic.xml: (actually put a picture)

<? XML version= "1.0" encoding= "Utf-8" ?> <  xmlns:android= "http://schemas.android.com/apk/res/android"    Android:layout_ Width= "200DP"    android:layout_height= "200DP"    android:src  = "@drawable/ic_launcher"/>

Slidingmenu.xml: (Layout file with side-slip 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" >    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "00000" /></LinearLayout>

The following is the code in the activity:

@Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub        Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Slidingmenu=(Slidingmenu) Findviewbyid (r.id.slidingmenulayout);        Slidingmenu.setmode (Slidingmenu.left); //Set the slide -by layoutSlidingmenu.setmenu (R.layout.slidingmenu); Slidingmenu.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {if(Slidingmenu.ismenushowing ()) Slidingmenu.toggle ();            }        }); }

The results of the operation are as follows:

The following are the common properties of Slidingmenu:

  • viewAbove-a reference to the layout, want to use as the above view of the Slidingmenu
  • viewBehind-a reference to the layout, want to use as the behind view of the Slidingmenu
  • touchModeAbove-an enum, that designates, the touchable when the above view is showing. Margin means only the left margin. Fullscreen means the entire screen. Default is margin.
  • behindOffset-a dimension representing the number of pixels so want the above view to show when the behind view is showing. Default is 0.
  • behindWidth-a dimension representing the width of the behind view. The Default is the width of the "screen" (equivalent to Behindoffset = 0).
  • behindScrollScale-a float representing the relationship between the above view scrolling and the behind behind view scrolling. If set to 0.5f, the behind view would scroll 1px for every 2px, the above view scrolls. If set to 1.0f, the behind view would scroll 1px for every 1px, the above view scrolls. And if set to 0.0f, the behind view would never scroll; It'll be static. This one was fun-to-play around with. Default is 0.25f.
  • shadowDrawable-a reference to a drawable to being used as a drop shadow from the above view onto the below view. Default is no shadow for now.
  • shadowWidth-a dimension representing the width of the shadow drawable. Default is 0.
  • fadeEnabled-A Boolean representing whether or not the behind view should fade when the Slidingmenu was closing and "Un-fade" when Ope Ning
  • fadeDegree-a float representing the "amount" of fade. 1.0f would mean fade all the "the" to black when the Slidingmenu is closed. 0.0f would mean does not fade at all.
  • selectorEnabled-A Boolean representing whether or not a selector should is drawn on the left side of the above view showing a selected V Iew on the behind view.
  • selectorDrawable-a reference to a drawable to being used as the selector note:in order to has the selector drawn, you must call Slidingme Nu.setselectedview (view v) with the selected view. Note that this would most likely does work with items in a ListView because of the the the "the" Android recycles item views.

There are some time to check it again.

Simple implementation of the Android slide menu (slidingmenu) II

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.