Detailed explanation and simple example of Android custom ViewGroup (sideslip menu)

Simple implementation of custom sideslip menu

Many apps have such sideslip menus, such as QQ, and more famous open source libraries such as slidingmenu.

If you are interested, you can study this open source library.

Here we will find our own implementation method to make a record of what we have learned, O (∩∩) O!

First look at the renderings:

The sideslip menu we implemented here is realized by taking the hidden menu on the left and the main panel as a whole, and the hidden menu on the left and the main panel are equivalent to the sub views of this custom view.

First, construct the layout of the custom view:

The customized slidemenview contains two sub views, one is menuview and the other is mainview (main panel).

Then we need to implement the Java code of slidemenview.

To customize a view, you need to inherit a parent class and enhance the function of the parent class by overriding some methods of the parent class.

Here, we choose to inherit the ViewGroup. Generally, we customize the view. We need to rewrite onmeasure, onlayout and OnDraw. Under normal circumstances, we only need to rewrite OnDraw. Under special circumstances, we need to rewrite onmeasure and onlayout.

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