About Android View and Drawable

Source: Internet
Author: User

Problem description:

When the View. invalidate () method is called, the View is requested to re-draw (). However, I have read the invalidate () and related methods, and there is no direct relationship with draw. How does invalidate () redraw a View?

The Drawable. mutate () method directly returns itself to avoid generating new objects. In this case, why can the same image resource have different normality (such as transparency) after mutate )? In BitmapDrawable, A BitmapState is generated during the first mutate () process, followed by a direct return of itself. The first normal object has changed, but I still don't understand it later. Thank you!

Solution:

1: The refreshing principle of invalidate is complicated.

Invaliddate => parent view => Handler => export mtraversals () => draw () => onDraw ();

[Java]
/* ============================== Detail ============ ======================================
Its inherited parent, views cheduleTraversals (), sends messages to Handler.
ViewRoot processes its messages
Case DO_TRAVERSAL:
Extends mtraversals ();
Call the performTraversals () method and call private void draw (boolean fullRedrawNeeded)
Including
MView. draw (canvas );
Next
If (! DirtyOpaque) onDraw (canvas );
*/

/* ============================== Detail ============ ======================================
Its inherited parent, views cheduleTraversals (), sends messages to Handler.
ViewRoot processes its messages
Case DO_TRAVERSAL:
Extends mtraversals ();
Call the performTraversals () method and call private void draw (boolean fullRedrawNeeded)
Including
MView. draw (canvas );
Next
If (! DirtyOpaque) onDraw (canvas );
*/
 

2: not to save memory. On the contrary, the native drawable is to share part of the data, but to save memory.
The shared part is the constant state (normal)
You think, N images use a normal state. If I want to change this value, for example, Alpha, all images change, just like
The static variable is the same.
After mutate is used, the constant state will be copied, and drawable will still be shared. This solves a "bug" for versions earlier than 1.5"

 

Related Article

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.