Understanding of the layout and Drawing Process of the view component and the drawing of drawable

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.