Android sideslip menu control drawerlayout usage details

Drawerlayout is a layout control with sideslip function under Android V4 package. It can expand and hide the sidebar according to gestures, or change the content of the main interface area with the click of the sidebar. And you only need to layout according to the layout format specified in drawerlayout to achieve the left and right sideslip effect.

1、 Agreed drawer layout

The layout of drawerlayout is generally divided into three parts: the first part is the main interface content layout, the second part is the left side sliding interface layout, and the third part is the right side sliding interface layout. So how does the system distinguish between left sideslip and right sideslip code blocks? Note that the code block of the sideslip part of the drawerlayout layout must specify Android: layout_ Gravity attribute, layout_ Gravity = "start / left" stands for left sideslip, layout_ Gravity = "end / right" stands for right sideslip. Drawerlayout is recommended in the official document as the root layout of the interface, otherwise the touch event may be blocked. The layout of the main content area in drawerlayout should be placed at the top level, then the left side sliding interface layout, and finally the right side sliding interface layout. Similar layout is as follows:

2、 Monitoring of drawerlayout

There are three types of listeners for drawerlayout. The method of adding a listener to drawerlayout is drawerlayout. Adddrawerlistener(). Because the expansion and hiding of the sideslip menu in drawerlayout can be monitored, we can do something we want to do when the expansion and hiding of the sideslip menu occur. (PS: drawerlayout. Setdrawerlistener() is obsolete, but it can still be used, the same as drawerlayout. Adddrawerlistener())

1. Listening with drawerlistener

2. Listening with simpledrawerlistener

As the name suggests, it is a simplified version of drawerlistener. It is not necessary to implement all the callback functions of drawerlistener. You can choose to rewrite the corresponding methods according to business needs. The usage is the same as that of drawerlistener.

3. Actionbardrawertoggle monitoring used with actionbar

If there is an actionbar in the activity, you'd better use actionbardrawertoggle to listen. Actionbardrawertoggle implements drawerlistener, which can do all the things that drawerlistener can do. However, if you use actionbardrawertoggle to listen, you need to select the override method. (supplement: 1. Drawerlayout. Opendrawer() and drawerlayout. Closedrawer() can open and close the sidebar. 2. If the click event of the sidebar penetrates the main interface, add Android: clickable = "true" on the outermost layer of the layout file of the sidebar.)

3、 Deficiency (or advantage?)

Compared with the general sideslip menu, the sideslip effect of drawerlayout will appear above the main interface. Unlike other sideslip menus, it will not obscure the main interface.

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
分享
二维码
< <上一篇
下一篇>>