Reference: Http://www.jianshu.com/p/3683a69c38ea
1, View.draw (Canvas) where the steps are:
/*
* Draw traversal performs several drawing steps which must be executed
* In the appropriate order:
*
* 1. Draw the background
* 2. If necessary, save the canvas ' layers to prepare for fading
* 3. Draw View ' s content
* 4. Draw Children
* 5. If necessary, draw the fading edges and restore layers
* 6. Draw Decorations (scrollbars for instance)
*/
2, Viewgroup.dispatchdraw (Canvas); If the control is ViewGroup or its subclasses, you need to draw a subclass
3, Viewgroup.drawchild (canvas canvas, View child, Long Drawingtime)
4, View.draw (canvas canvas, viewgroup parent, long drawingtime); This method implements animation
The following code snippet gets the animation matrix, Alipa equivalent
if (A! = null) {
more = Applylegacyanimation (parent, Drawingtime, A, scalingrequired);
Concatmatrix = A.willchangetransformationmatrix ();
if (Concatmatrix) {
MPRIVATEFLAGS3 |= Pflag3_view_is_animating_transform;
}
transformtoapply = Parent.getchildtransformation ();
The main method is Applylegacyanimation, whose code snippet
Final Transformation T = parent.getchildtransformation (); Remove the transformation object saved by the parent control
Boolean more = A.gettransformation (Drawingtime, T, 1f); Fills the object T with the matrix change value in animation; Where A is an animated object set by the programmer
Gettransformation Code snippet for Animation
Final float interpolatedtime = minterpolator.getinterpolation (normalizedtime);
Applytransformation (Interpolatedtime, outtransformation); Fill in the method of passing parameter transformation, it is an empty method, the implementation of the subclass is responsible for the specific
For example: Rotateanimation's Applytransformation method, where the code snippet:
Float degrees = mfromdegrees + ((mtodegrees-mfromdegrees) * interpolatedtime);
Float scale = Getscalefactor ();
if (Mpivotx = = 0.0f && Mpivoty = = 0.0f) {
T.getmatrix (). setRotate (degrees);
} else {
T.getmatrix (). SetRotate (degrees, Mpivotx * scale, mpivoty * scale); Set the rotation angle to the transformation matrix, and the other subclasses are similar logic
}
View.draw (,,) the code snippet that really animates:
Canvas.translate (-TRANSX,-transy);
Canvas.concat (Transformtoapply.getmatrix ()); Pass the matrix taken out of the animation to the canvas for an animated effect
Canvas.translate (TRANSX, Transy);
Fast path for layouts with no backgrounds
if ((Mprivateflags & pflag_skip_draw) = = Pflag_skip_draw) {
Mprivateflags &= ~pflag_dirty_mask;
} else {
Draw (canvas);//After performing an animated transform, then draw the view
}
Conclusion:
1, Animation animation plays a key role in the class is transformation, Animation is responsible for the calculation of animation matrix transformation, transformation is responsible for transferring the transformation to the canvas.
2, Animation animation just made a matrix transform to canvas, and did not modify its property values, which is the biggest difference between it and the property animation.
3, the alpha value modification also saves the layer in the draw method, does not affect the property value
Android Animation Animation drawing logic