Detailed explanation of Android slidingmenu usage and examples

Many apps have the function of sideslip menu, and some apps have sideslip menu on the left and right ~ slidingmenu this open source project can help us realize the sideslip function. If you don't know much about slidingmenu, you can refer to this blog. There are many ways to introduce the sideslip menu into the project. This blog first introduces various introduction methods through examples, and then shows you an example: the main layout viewpager and the usage of one sideslip menu on the left and right can almost meet the needs of most applications. Common attributes are described at the end of the article.

1. In the activity, the sideslip menu is directly set through the slidingmenu construction method

design sketch:

Is it particularly simple ~ a few lines of code ~ ha~

2. By inheriting activity from slidingactivity

a. Inherit slidingactivity

b. Then set the behind content view (r.layout. Leftmenu) in oncreate; Sets the layout of the sideslip menu

c. Get the slidingmenu object through getslidingmenu(), and then set the style

The rendering is the same as the first method ~ is it also very simple~~

3. Treat slidingmenu as a normal control

You can take slidingmenu as an ordinary view, and then declare it in the layout to play madly ~ here is an example:

As an ordinary view, we set the layout in the layout file, and set the value of viewabove to another layout.

Let's look at the pic layout:

It's a picture of a girl.

Finally, look at the main activity:

design sketch:

Through slidingmenu, you can set a sliding display introduction for pictures. You can also slide display anything, download and share buttons. I don't know the efficiency of many pictures. I can play like this, but I don't recommend it~

4. Slidingmenu example of setting left and right sideslip menus

For the three methods described above, the events of controls in the layout of slidingmenu need to be written in the activity, so the code is cumbersome. Generally, fragment is used as the layout container of sideslip menu.

Core code:

First, set the sideslip menu through setbehindcontentview (r.layout. Left_menu_frame); Set a layout in which there is only one FrameLayout, and then use the fragment manager to replace the fragment, so that the fragment will be used as the layout of our sideslip menu, and our event handling code can also be written in the frame instead of the activity.

Here are some specific examples:

First, there are two fragments on the left and right sides:

MenuLeftFragment

The sideslip layout on the left is a listview, and the code is relatively simple~

MenuRightFragment

The fragment of the sideslip menu on the right loads a layout without any event processing~

Finally, mainactivity

Briefly, mainactivity inherits slidingfragmentactivity. In the activity, fragmentpageradapter and viewpager are used as the main layout, and then the menus on both sides of slidingmenu are initialized respectively.

design sketch:

Ha ha, wechat is lying on the gun again ~ ~ this example should meet the needs of general apps.

5. Some common properties of slidingmenu

There are also several listening events:

There are other things to check when you need them~

I packed all the above examples, including the Lib of slidingmenu ~: demo

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>