View and ViewGroup for Android view control architecture analysis

In Android, view controls are roughly divided into two categories: ViewGroup and view. As the parent control, ViewGroup control contains and manages child views. The control tree is formed through ViewGroup and view. Each viewgoup object and view object are the nodes in the control tree. In the control tree, the depth of the tree is used to traverse and find the corresponding control elements. At the same time, the upper control is responsible for the measurement and drawing of child controls and passing interactive events.

Android control tree:

Android UI interface architecture diagram:

1、 Tool class of measurement view: measurespec

1. Measurespec includes the measurement mode and measurement size. Obtain the measurement mode through measurespec. Getmode() and the measurement size through measurespec. Getsize();

2. Measurespec is a 32-bit int value. The upper 2 bits are the measurement mode and the lower 30 bits are the measurement size. The purpose of using bit operation is to improve the optimization efficiency.

2、 Measurement mode

1. Exctly, exact value mode: Layout_ Width or layout_ The height attribute is specified as a specific value or match_ parent。

2.AT_ Most, maximum mode: Layout_ Width or layout_ Height is specified as wrap_ content。

3. Unspecified: view can be as big as it wants

3、 The default onmeasure() method of view class only supports the actual mode. If you want to support other modes, you must override onmeasure(), and override the template code of onmeasure():

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