Detailed explanation of the use method of Android native sideslip control drawerlayout

In the V4 package of Android, there is a control drawerlayout, which mainly realizes the left and right pull menus, similar to the previous "drawer" function. This control is simple to use, the effect is very soft, and the operation experience is very good. The following is a partial screenshot of a simple effect I implemented:

Zola:

Right pull:

What about? Is it common in applications developed at ordinary times? OK, then I'll go directly to the code:

activity_ sliding.xml:

Through the above layout file, we find that the sub layout in the drawerlayout is divided into three parts: content, left and right. The left and right layouts need to declare Android: Layout in the layout_ Gravity attribute, with values of start and end respectively. Obviously, the drawer layout is similar to a large container, super screen layout, which places the left layout at the beginning of the control and the right layout at the end of the control.

DrawerSlidingActivity.java:

The first thing to note is: drawerlayout.setscrimcolor (color. Transparent). This attribute sets the background color of the area outside the content when the sideslip layout is displayed. The default is gray. Here I set it to be transparent for everyone to see clearly; The second is the listener actionbardrawertoggle of drawerlayout, and the actionbardrawertoggle object. By consulting the source code of actionbardrawertoggle, we found that it is the implementation class of drawerlistener, that is, actionbardrawertoggle implements drawerlistener listening, and encapsulates ondraweropened, ondrawerclosed Ondrawerstatechanged and ondrawerslide event processing, so that developers can customize some operations to be processed during the sliding process.

Finally, check whether your as is the latest version. If not, you need to add the following configuration in build.gradle:

compile 'com.android.support:appcompat-v7:24.2.1'

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