The Android View component shows the three processes, mainly through Mesure, layout, and draw. In the Mesure phase call mesure (int widthspec, int heightspec) method, this method is final cannot be rewritten, in this process will call onmesure (int widthspec, int heightspec) Method. When the component is set to a size, call the final layout (int l, int t, int r, int b) method to lay out, and in this process call OnLayout (Boolean changed, int l, int t, int r, int b) method, the layout of the processing component is usually overridden by the onmesure and OnLayout methods.
the drawing of the view component calls the draw (canvas canvas) method, which in the source code does not see where the call is made ... the main draw process is the first drawable background, Call SetBounds () to drawable and then the draw (Canvas C) method. A little bit of note is that the actual size of the background drawable affects the size of the view component, and the actual size of the drawable is Getintrinsicwidth () and Getintrinsicheight () gets, when the background is larger, the view component size equals the size of the background drawable, but I did not call the getintrinsicwidth () and Getintrinsicheight () method ...
After drawing the background, the draw process calls the OnDraw (canvas canvas) method, and then the Dispatchdraw (Canvas canvas) method, Dispatchdraw () is mostly distributed to sub-assemblies for drawing, and we typically override the OnDraw () method when customizing components. It is noteworthy that the ViewGroup container component is drawn, and when it does not have a background, it calls the Dispatchdraw () method directly, bypassing the draw () method, invoking the draw () method when it has a background, and draw () The method contains a call to the Dispatchdraw () method. So the Dispatchdraw () method instead of the OnDraw () method is often overridden to draw on ViewGroup, or a drawable is customized, the draw (Canvas C) and the getintrinsicwidth (),
Getintrinsicheight () method, then set as background
Android View component Draw Ondraw,dispatchdraw