Android Slidingmenu Use detailed

Source: Internet
Author: User

Slidingmenu is the side-by-side interface in the Android program, and the system comes with the Drawerlayout function is the same, mainly the visual effect is not the same, the mobile phone version of QQ using the side-slip interface is Slidingmenu

Preliminary use method: to realize slide-out effect of slide-slip interface

Step one: Download the Slidingmenu class library file and import it into the project.

Slidingmenu Class Library Network disk:

Link: https://pan.baidu.com/s/1df7GKm Password: vg50

Import the library from the downloaded Slidingmenu-master file into the current project

After import, note that the following information in the library's Build.gradle is modified to match the current project

After that, you may report a mistake, showing that Floatmath has expired, and manually changing the Floatmath to math.

Step two: After the successful import of the class library can be used in Java code slidingmenu This class, through Java code implementation of the side-slip interface effect

First, the layout in Activity_main.xml:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    xmlns:app=" Http://schemas.android.com/apk/res-auto "    xmlns:tools=" http://schemas.android.com/ Tools "    android:layout_width=" match_parent "    android:orientation=" vertical "    android:background=" # ed0e0e "    android:layout_height=" match_parent "    tools:context=" com.contentprovide.liuliu.slidmingmenu_4. Mainactivity ">    <button        android:id=" @+id/button "        android:layout_width=" Match_parent        " android:layout_height= "Wrap_content"        android:text= "button"/></linearlayout>

the slide-by interface requires a reference to the custom resource layout slid.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" match_parent "    android:orientation=" vertical ">   <textview       Android:layout_width= "Wrap_content"       android:layout_height= "wrap_content"       android:text= "I am sliding interface"       / ></LinearLayout>

Java code implementation:

Package Com.contentprovide.liuliu.slidmingmenu_4;import Android.os.bundle;import Android.support.v7.app.appcompatactivity;import Android.view.view;import Android.widget.button;import Com.jeremyfeinstein.slidingmenu.lib.slidingmenu;public class Mainactivity extends Appcompatactivity {slidingmenu    Slidingmenu;    Button button;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Button = (button) Findviewbyid (R.id.button); Slidingmenu = new Slidingmenu (this);//Set Rendering mode Slidingmenu.setmode (slidingmenu.left);//render mode to the left//set the slip boundary The size of the Slidingmenu.setbehindoffset (200);//Set Full screen can touch Slidingmenu.settouchmodeabove (slidingmenu.touch        Mode_fullscreen);//Add to Current Activity slidingmenu.attachtoactivity (this, slidingmenu.sliding_content);// Refer a layout resource to the side-slip interface as the interface Slidingmenu.setmenu (r.layout.slid);//Add a button to the main interfaceevent, click the Slide Out menu Button.setonclicklistener (new View.onclicklistener () {@Override public void onclic            K (view view) {Slidingmenu.toggle (true);    }        }); }}

Implementation results:

Slidingmenu Common Properties

Set the position of the side-slip menu, optional values left, right, Left_right (set when both sides have menus)

Menu.setmode (Slidingmenu.left_right);

Set the mode of touch screen, optional only margin, CONTENT
Menu.settouchmodeabove (Slidingmenu.touchmode_margin);

Sets the width of the shadow according to the ID of the dimension resource file
Menu.setshadowwidthres (R.dimen.shadow_width);

Sets the shadow effect of the swipe menu based on the resource file ID
Menu.setshadowdrawable (R.drawable.shadow);

Both of these are set to the width of the sliding menu view, and the second option
Set the offset of the slidingmenu from the screen
Menu.setbehindoffsetres (R.dimen.slidingmenu_offset);
Set width
Menu.setbehindwidth ()

Set the value of the fade-in fade-out effect
Menu.setfadedegree (0.35f);

Sets the speed ratio of the slidingmenu to the movement of the lower view, when the 1 o'clock moves simultaneously, the value 0-1
Menu.setbehindscrollscale (1.0f);

Set the shadow effect on a level two menu
Menu.setsecondaryshadowdrawable (R.drawable.shadow);

Set the right side (level two) Slide menu
Menu.setsecondarymenu (R.layout.right_menu_frame);

To set the layout for the slide menu
Menu.setmenu (R.layout.leftmenu);

Add sliding menu to all activity, optional value sliding_content, Sliding_window
Menu.attachtoactivity (this, slidingmenu.sliding_content);

Advanced usage: Add events to various spaces in the layout in Slidingmenu and use fragment

After sliding the slide-out interface We need to do the next step in the side-slip interface so that the events in the layout in the slide-in interface will be written separately.

by Sermenu (a) method to the side-slip interface refers to the layout interface A.xml, in this a.xml layout interface There is only one framelayout, the side-by-side interface of all the code is written in fragment, and then by using Fragmentmanager to replace fragment this fragment, which is quite The SetMenu method refers to the fragment.

Implementation results:

Android Slidingmenu Use detailed

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.