Slidingmenu open-source project

Source: Internet
Author: User

Setup-Installation

1. In eclipse, you only need to introduce the library into the android library project. Select project-> clean to generate binary data required by your project, such as R. java.

2. Then, add the slidingmenu to your project reference.

Note: It is troublesome to add a project reference. The following describes how to add a project reference:

A. Download the zip package. : Https://github.com/jfeinstein10/slidingmenu. After the webpage is opened, download it to the right,

B. decompress the package and import the library project to the workspace of your project. The import method is: New-> Android project from existing code, and select the library project.

C. Right-click your project, choose Properties> Android, click Add library in the lower right corner, and select the Library Project imported in step B.

Note: If you use a support-v4 package in your project, an error may be reported after completing the three steps above. This is because the support-v4 packages used in the slidingmenu project are inconsistent with the support-v4 packages used in your project. Make the two packages the latest error to disappear.

Setup with actionbarsherlock

1. Follow the steps 1 and 2 above to import the actionbarsherlock Library Project (the project name is not necessarily called) to your workspace.

2. Add actionbarsherlock as a reference of the slidingmenu project.

3. Open the slidingactivity Java file of the slidingmenu project and modify the class to inherit from the sherlockactivity instead of the original activity.

How to integrate this library into your projects-how to integrate the library into your project

To integrate the library of slidingmenu into your project, you can select any of the following methods:

1. you can use the new slidingmenu (context) method to include your activity in a slidingmenu, and then call slidingmenu. attachtoactivity (activity, slidingmenu. sliding_window | slidingmenu. sliding_content) method. Sliding_window will contain actionbar in the content part of slidingmenu, but sliding_content will not. You can join attachexample In the example project.

2. You can let your activity inherit slidingactivity to embed slidingmenu at the activity level.

2.1 In the oncreate () method of your activity, call the setcontentview () method as usual, and call the setbehindcontentview () method. It has the same syntax structure as the setcontentview () method. The setbehindcontentview () method places the view behind the slidingmenu. You can also use the getslidingmenu () method, so that you can customize your linked slidingmenu.

2.2 If you want to use other libraries, such as actionbarsherlock, you only need to change the inheritance relationship of slidingactivity so that it can inherit from sherlockactivity. The original inheritance is activity.

3. You can use slidingmenu in Java code or in XML layout files.

3.1 you can use slidingmenu as another view type and place it in a great place, such as the row of listview.

3.2 I can, everything is possible! Pai_^

Simple Example-simple example


Public class slidingexample extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); settitle (R. string. attach); // set the content view-set the content view setcontentview (R. layout. content); // configure the slidingmenu-configure slidingmenu menu = new slidingmenu (this); menu. setmode (slidingmenu. left); menu. settouchmodeabove (sregistringmenu. 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. menu );}}

XML usage-XML usage

If you decide to regard slidingmenu as a view, you can define it in the XML file:

<com.jeremyfeinstein.slidingmenu.lib.SlidingMenu    xmlns:sliding="http://schemas.android.com/apk/res-auto"    android:id="@+id/slidingmenulayout"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    sliding:viewAbove="@layout/YOUR_ABOVE_VIEW"    sliding:viewBehind="@layout/YOUR_BEHIND_BEHIND"    sliding:touchModeAbove="margin|fullscreen"    sliding:behindOffset="@dimen/YOUR_OFFSET"    sliding:behindWidth="@dimen/YOUR_WIDTH"    sliding:behindScrollScale="@dimen/YOUR_SCALE"    sliding:shadowDrawable="@drawable/YOUR_SHADOW"    sliding:shadowWidth="@dimen/YOUR_SHADOW_WIDTH"    sliding:fadeEnabled="true|false"    sliding:fadeDegree="float"    sliding:selectorEnabled="true|false"    sliding:selectorDrawable="@drawable/YOUR_SELECTOR"/>

Note: you cannot use behindoffset or behindwidth. If you do this, the program will throw an exception.

* Viewabve: reference of the layout you want to use on the slidingmenu

* Viewbehind: reference of the layout you want to use under slidingmenu

* Touchmodeabove: an enum. When the view above is displayed, it specifies which part of the screen is touchable. Margin indicates only the left edge. Fullscreen indicates the entire screen. The default value is margin.

* Behindoffset: When a view is displayed, you want to display the pixel size of the view above it. The default value is 0.

* Behindwidth: the size of the rear view width. The default value is the screen width (equivalent to behindoffset = 0 ).

* Behindscrollscale: A floating point value that represents the relationship between view scrolling above and view scrolling below. If it is set to 0.5f, the view above will scroll 2px each time, and the view following will scroll 1px. If it is set to 1.0f, the view above will scroll 1 px, And the view following it will also scroll 1 px. If it is set to 0.0f, the subsequent view will not scroll, that is, it is static. This is an interesting thing. The default value is 0.25f.

* Shadowdrable: a reference to the drawable shadow between the above view and the following view. No shadow by default.

* Shadowwidth: represents the size of the Shadow drawable width. The default value is 0.

* Shadowenable: whether to disable slidingmenu in fade mode when it is enabled in non-Fade mode.

* Fadedegree: A floating point value that represents the "quantity" of fade ". 1.0f means that fade will always exist when slidingmenu is disabled. 0.0f means there will be no fade.

* Selectorenable: A boolean value that identifies whether to draw a selection item on the left of the view above to show the selected elements of the view.

* Selectordrawable: used to select the drawable reference. Note: In order for the selected item to be drawn, you must call the slidingmenu. setselectview (view v) method on the selected view. In listview, list items are likely not to work because Android recycles them.

Caveats-Additional instructions

Your layout must be based on viewgroup. Unfortunately, this approach violates the optimization of <merge>.

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.