Some brief notes on Android draw, OnDraw, Dispatchdraw, invalidate, Computescroll

Source: Internet
Author: User

In view:

public void Draw (canvas canvas) {

/*

1. Draw the background background

2. If necessary, save the canvas ' layers to prepare for fading if necessary, color fades before saving the canvas layer (that is, locking the original canvas content)

3. Draw view's content drawing view

4. Draw Children Drawing Sub View

5. If necessary, draw the fading edges and restore layers if necessary, paint the color gradient light border and restore the canvas (that is, the canvas changes the content attached to the original content)

6. Draw decorations (scrollbars for instance) to paint decorations, such as scroll bars

*/

...

if (!dirtyopaque) {

Drawbackground (canvas); Background drawing

}

Skip Step 2 & 5 if possible (common case) usually skip steps 2nd and 5th

...

if (!dirtyopaque) OnDraw (canvas); Call OnDraw

Dispatchdraw (canvas); Draw Child View

Ondrawscrollbars (canvas); Draw scroll bars

...

}

protected void Dispatchdraw (canvas canvas) {//NULL implementation}

protected void OnDraw (canvas canvas) {//NULL implementation}

In ViewGroup:

protected void Dispatchdraw (canvas canvas) {

...

Drawchild (...); Draw Child View

...

}

Protected Boolean drawchild (canvas canvas, View child, long Drawingtime) {

Return Child.draw (canvas, this, drawingtime);

}

Description

1. When customizing a view, rewrite OnDraw.

Calling View.invalidate () will trigger OnDraw and Computescroll (). If the view is attached to the current window

View.postinvalidate (); is called on a non-UI thread.

2. Customize a viewgroup, rewrite OnDraw.

OnDraw may not be called because a background (color or graph) needs to be set first.

Indicates that the group has something to draw before it triggers draw and then OnDraw.

Therefore, the general direct rewrite Dispatchdraw to draw ViewGroup

3. Customizing a ViewGroup

Dispatchdraw will call Drawchild.

http://blog.csdn.net/jjwwmlp456/article/details/43986141

Android draw, OnDraw, Dispatchdraw, invalidate, computescroll some brief notes (GO)

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.