The difference between the Android update view function OnDraw () and Dispatchdraw ()

Source: Internet
Author: User

Draw the contents of the View itself , by calling the View.ondraw (canvas) function to implement

Draw your own child through dispatchdraw (canvas) to achieve

The drawing of the view component invokes the draw (canvas canvas) method, in which the drawable background is drawn primarily, the drawable is called SetBounds (), and then the draw (canvas C) method. It is important to note that the actual size of the background drawable affects the size of the view component, and the actual size of the drawable is obtained through Getintrinsicwidth () and Getintrinsicheight (). The size of the view component is equal to the size of the background drawable when the background is relatively large.

After drawing the background, the draw process calls the OnDraw (canvas canvas) method, then the Dispatchdraw (Canvas canvas) method, andDispatchdraw () is mostly distributed to the child components for drawing . We usually rewrite the OnDraw () method when customizing the 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 , rather than the OnDraw () method, is often overridden to draw something on ViewGroup, or a drawable is customized, the draw (Canvas C) is rewritten, and Getintrinsicwidth (), Getintrinsicheight () method, and then set as background.

The difference between the Android update view function OnDraw () and Dispatchdraw ()

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.