The view component of Android is displayed mainly through three processes: mesure, layout, and draw. In the mesure stage, call the mesure (INT widthspec, int heightspec) method. The final method cannot be overwritten. In this process, the onmesure (INT widthspec, int heightspec) method is called. After the component size is set, call the final layout (int l, int T, int R, int B) method for layout. In this process, onlayout (Boolean changed, int L, int T, int R, int B) method. Therefore, the onmesure and onlayout methods must be rewritten to process the layout of components.
The drawing of the view component calls the draw (canvas) method, which is invisible in the source code... in the draw process, draw the drawable background first, call setbounds () for the drawable, and then use the draw (canvas c) method. note that the actual size of the background drawable will affect the size of the view component. The actual size of the drawable is obtained through getintrinsicwidth () and getintrinsicheight, when the background is large, the size of the view component is equal to the size of the background drawable, but the layout is not found in the source code.
Getintrinsicwidth () and
Getintrinsicheight () method...
After the background is drawn, the draw process calls the ondraw (canvas) method, and then the dispatchdraw (canvas) method. The dispatchdraw () method is mainly distributed to the child component for painting, we usually override the ondraw () method when customizing components. It is worth noting that the viewgroup container component is drawn. When there is no background, the dispatchdraw () method is called directly, and the draw () method is bypassed, when there is a background, the draw () method is called, while the draw () method contains the call of the dispatchdraw () method. Therefore, the dispatchdraw () method rather than the ondraw () method is often rewritten when drawing on viewgroup, or a drawable is customized, its draw (canvas C) and
Getintrinsicwidth (),
Getintrinsicheight () method, and then set it as the background.