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"