Drawerlayout developed by Android to achieve drawer effect

Google officially launched a sideslip menu implementation method (drawer effect), that is, drawerlayout. This class is in the support library, and the package android-support-v4.jar needs to be added.

Precautions for use

1. The first child element of drawerlayout must be the default content, that is, the layout displayed when the drawer is not opened (such as FrameLayout), and the next child element is the drawer content, that is, the drawer layout (such as listview).

2. The drawer menu is placed and arranged through Android: layout_ Gravity attribute. The optional values are left, right or start, end.

3. The width of the drawer menu is DP units and the height is the same as the parent view. The width of the drawer menu should not exceed 320dp, so that users can see part of the content interface when the menu is opened.

4. Open drawer: drawerlayout. Opendrawer(); Close drawer: drawerlayout. Closedrawer();

A typical layout example:

The listview is stored here, and the navigationview launched with Android m will be described below

Problems encountered

1. When you click the blank space in the drawerlayout, the content at the bottom will get the event.

Because Google's demo is a listview, the listview will get the focus, the event will not be transmitted, and the problem can not be seen. However, if the layout is loaded with the include, this situation will occur. How to solve it?

Solution: in the layout of include, add clickable = true

2. Where is the view other than the layout view of the drawer

The left and right drawers and middle content views are not displayed by default. Other layout views will be displayed directly, but they need to be placed inside the drawerlayout before they can be used normally (not outside). Otherwise, they either overlap each other, or touch screen events and scrolling will fail.

3. Remove the gray background of the content display page after the left and right drawers are marked out?

drawerLayout.setScrimColor(Color.TRANSPARENT);

4. How to fill the space between the drawer and the edge of the screen (i.e. the gray part above)?

drawerLayout.setDrawerShadow(Drawable shadowDrawable,int gravity)

drawerLayout.setDrawerShadow(int resId,int gravity)

Implement drawer menu with navigationview

Navigationview is a new MD style component proposed in Android M. it divides itself into two, displays a general layout above and a set of menus below. It can be used together with drawerlayout to realize the general sideslip menu. The layout is as follows

Header.xml, very simple

menu_ drawer_ Left. XML to construct four simple menus

Implementation effect diagram

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