"Android Interface Implementation" Slidingmenu the latest version number using the specific explanation

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/zhaokaiqiang1992

In an article that was a long time ago, a brief introduction to the use of the Open source project Slidingmenu control, this article will be more specific about the usage of the Slidingmenu control that describes the latest version number.

Slidingmenu's github address: Https://github.com/jfeinstein10/SlidingMenu


Integrate Slidingmenu into your project

Before we can use an open source project, we need to introduce the project as a resource into our current project. Before you integrate, download the demo sample code for the project on GitHub. Import into Eclipse. About importing an external project into the current project. There are two ways of doing this.

(1) Set the resource project as a library to our project, just like examplelistctivity in the sample code, as seen in.

One thing you need to pay attention to. Because Actionbarsharlock is used in the Slidingmenu Demo sample code, this relies on project. Therefore, we need not only the Slidingmenu code. a Actionbarsharlockproject resource project is also required. Actionbarsharlock's GitHub project address is https://github.com/JakeWharton/ActionBarSherlock you can download it yourself.

After we've set up a dependency on project, we're ready to use Slidingmenu.


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvemhhb2thaxfpyw5nmtk5mg==/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/center ">


(2) In addition to the use of the above-dependent project method, we can also directly rely on project, that is, the library project inside the code, directly copied into our target project. I personally prefer this approach, although this adds the volume of the project's installation package, however. It is more convenient for the management of the project.

In this project. We will be able to copy the following file into our project.




How to add Slidingmenu controls

(1) Inherit from slidingfragmentactivity. Suppose it is in this way. Our activity needs to be inherited from slidingfragmentactivity. Slidingfragmentactivity is a class within the slidingmenu. Inherit from it, we can have a slidingmenu control.

Let's say we want to use this method to refer to the following code.

Package Com.example.slidingmenudemo;import Android.os.bundle;import android.support.v4.app.FragmentTransaction; Import Com.jeremyfeinstein.slidingmenu.lib.slidingmenu;import com.jeremyfeinstein.slidingmenu.lib.app.slidingfragmentactivity;/** * Inherits from Slidingfragmentactivity's side slider, The ability to achieve the side slider bar is the effect of the fragment side slider * * @author Zhaokaiqiang * @see http://blog.csdn.net/zhaokaiqiang1992 * */public class MethodOne Activity extends Slidingfragmentactivity {@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate ( savedinstancestate);//Set the layout file of the main interface Setcontentview (r.layout.activity_method_one);// Set the layout file for the container that holds the sidebar setbehindcontentview (r.layout.frame_menu);//fill the Fragment class of the slider bar into the layout file of the container in the sidebar fragmenttransaction Transaction = Getsupportfragmentmanager (). BeginTransaction (); Samplelistfragment fragment = new Samplelistfragment (); Transaction.replace (r.id.menu_frame, fragment); Transaction.commit ();//Gets the Slidingmenu object. Then set some common properties Slidingmenu sm = Getslidingmenu ();//Set the width of the shadow Sm.setshadowwidth (0);//Set the color of the shadow Sm.setsHadowdrawable (R.drawable.shadow);//Set the side slider to fully expand. Distance from the other side, unit px, the larger the width of the slider bar sm.setbehindoffset (100);//the degree to which the gradient is set. The range is 0-1.0f, the larger the setting. When the side slider is just out of the box. The darker the color is. When 1.0f, the color is All Black sm.setfadedegree (0.3f);//set Touch mode. The ability to select a full screen or an edge to underline. Or it is not sm.settouchmodeabove (slidingmenu.touchmode_fullscreen);//Set whether Actionbar can be moved with the side slider, assuming no, You can remove setslidingactionbarenabled (false);}}

Use this method of implementation. Our slide bar is implemented using a fragment. PassSetbehindcontentview () method, we can set the container to place the side slider layout. This container is a very easy layout file, generally more fixed, for example, like the following can be

<?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"/>


In this case, a fragmentlayout layout with the ID set is available. So we can get throughtransaction.replace (r.id.Menu_frame, fragment) method fills the fragment of our sidebar into Slidingmenu.

As the slidingfragmentactivity inside has integrated a slidingmenu. So. We can get a Silidingmenu object by Getslidingmenu () and then set the properties that are used as the code above.

It is convenient to join Slidingmenu in this way, but we must inherit from slidingfeagmentactivity, there are some limitations.


(2) inherit from fragmentactivity

In addition to inheriting Slidingmenu's own activity, we are also able to directly inherit from Fragmentactivity, assuming this is the way to go. We are able to participate in the following code implementation.

Package Com.example.slidingmenudemo;import Android.os.bundle;import android.support.v4.app.FragmentActivity; Import com.jeremyfeinstein.slidingmenu.lib.slidingmenu;/** * Inherits from Fragmentactivity's side slider implementation, can realize the side slide bar is the effect of the side slider of fragment * @ Author Zhaokaiqiang * @see http://blog.csdn.net/zhaokaiqiang1992 */public class Methodtwoactivity extends fragmentactivity {private Slidingmenu menu; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_method_two); menu = new Slidingmenu (this); menu.setshadowwidth (0); menu.setshadowdrawable (R.drawable.shadow); Menu.setbehindoffset (+); Menu.setfadedegree (0.35f); Menu.settouchmodeabove (Slidingmenu.touchmode_fullscreen); Menu.attachtoactivity (This, SlidingMenu.SLIDING_ CONTENT); Menu.setmenu (R.layout.frame_menu); Getsupportfragmentmanager (). BeginTransaction (). Replace (r.id.menu_ Frame, new Samplelistfragment ()). commit ();}}

To integrate in this way, we need to customize the Slidingmenu. And then through Attachtoactivity. Connecting the Slidingmenu to our fragmentactivity, the SetMenu () method sets the layout of the container for our side slider. And the first method above is the same.


other frequently used attributes(1) Double side slide Barwe can use the following code to achieve the effect of the two-side slider bar
@Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);// Set the left side of the slider bar Getslidingmenu (). SetMode (Slidingmenu.left_right); Getslidingmenu (). Settouchmodeabove ( Slidingmenu.touchmode_fullscreen); Setcontentview (r.layout.content_frame); Getsupportfragmentmanager (). BeginTransaction (). Replace (R.id.content_frame, New Samplelistfragment ()). commit ();//Set the right side of the slider bar Getslidingmenu (). Setsecondarymenu (R.layout.menu_frame_two); Getslidingmenu (). setsecondaryshadowdrawable (R.drawable.shadowright); Getsupportfragmentmanager (). BeginTransaction (). Replace (R.id.menu_frame_two, New Samplelistfragment ()). commit ();}

(2) Setting touch modethroughGetslidingmenu (). Settouchmodeabove () canset the touch mode of the sidebar with the following 3 constant values

Slidingmenu. Touchmode_fullscreen Full Screen mode. Full screen swipe to open

Slidingmenu. Touchmode_margin side mode, only on the side of the screen sliding talent open, center slide can't open

Slidingmenu. Touchmode_none disables touch mode and cannot be opened by touch. Can only be opened or closed by Slidingmenu (). Toggle ()

(3) Setting the side slider display animationthroughSlidingmenu.setbehindcanvastransformer (Canvastransformer) method to set the display animation for the side slider, which is a Canvastransformer object. The following are the settings for several common animations
Collapse Animation
New Canvastransformer () {@Overridepublic void Transformcanvas (canvas canvas, float percentopen) {Canvas.scale ( Percentopen, 1, 0, 0);}}

Zoom in on animation
New Canvastransformer () {@Overridepublic void Transformcanvas (canvas canvas, float percentopen) {Float scale = (float) (PE rcentopen*0.25 + 0.75); Canvas.scale (scale, scale, canvas.getwidth ()/2, Canvas.getheight ()/2);}}

Rise animation
private static Interpolator Interp = new Interpolator () {@Overridepublic float getinterpolation (float t) {t-= 1.0f;return T * t * + 1.0f;}}; New Canvastransformer () {@Overridepublic void Transformcanvas (canvas canvas, float percentopen) {canvas.translate (0, Canvas.getheight () * (1-interp.getinterpolation (Percentopen)));}}

Many other properties of the other. Please check the demo sample code yourself.

"Android Interface Implementation" Slidingmenu the latest version number using the specific explanation

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.