The Android platform offers two types of animations. One is the tween animation, that is, the object in the scene constantly changing the image to produce animation effects (rotation, translation, indentation and gradient).
The second category is frame animation, which is the sequential playback of pre-made images, similar to the GIF picture principle.
Let's talk about Tweene animations.
Main classes:
Animation Animation
Alphaanimation Gradient Transparency
Rotateanimation Screen Rotation
Scaleanimation Gradient Size scaling
Translateanimation Position Movement
Animationset Animation Set
With these classes, how do we animate them?
In the case of custom view, the view is simple and there is only one picture on the screen. Now we are going to implement various tween animations for the entire view.
Alphaanimation
Implement alphaanimation through code, as follows:
1 // Initialize 2 New Alphaanimation (0.1f, 1.0f); 3 // Set Animation time alphaanimation.setduration (+); 4 This . Startanimation (alphaanimation);
Where the first parameter of the Alphaanimation class Fromalpha represents the transparency at the beginning of the animation, the second parameter Toalpha represents the transparency at the end of the animation.
The setduration is used to set the duration of the animation.
Rotateanimation
Code:
1 New rotateanimation (0f, 360f); 2 Rotateanimation.setduration (+); 3 This
Where the Rotateanimation class first parameter fromdegrees represents the angle at which the animation starts, the second parameter todegrees the angle at the end of the animation.
In addition, you can set the scaling mode Pivotxtype, Pivotytype, scaling animation relative to the beginning of x, y coordinates pivotxvalue, pivotyvalue, and so on.
Scaleanimation
Code:
1 // Initialize 2 New Scaleanimation (0.1f, 1.0f,0.1f,1.0f); 3 // Set animation time 4 scaleanimation.setduration (+); 5 This
In the Scaleanimation class
The first parameter is FROMX, and the second parameter tox: The scaling dimension on the x-coordinate at the beginning and end of the animation, respectively.
The third parameter is fromy, and the fourth parameter toy: The scaling dimension on the y-coordinate of the start and end of the animation, respectively.
In addition, you can set the scaling mode Pivotxtype, Pivotytype, scaling animation relative to the beginning of x, y coordinates pivotxvalue, pivotyvalue, and so on.
Translateanimation
Code:
1 // Initialize 2 New Translateanimation (0.1f, 100.0f,0.1f,100.0f); 3 // Set Animation time translateanimation.setduration (+); 4 This
Translateanimation class
The first parameter is Fromxdelta, and the second argument Toxdelta: The x-coordinate of the start and end of the animation, respectively.
The third parameter Fromydelta, the fourth parameter Toydelta: The start of the animation, the end of the y-coordinate.
Parameters Detailed Description:
|
Table II |
| XML node |
Function description |
| Alpha |
Gradient Transparency Animation effect |
<alpha
Android:fromalpha= "0.1″
Android:toalpha= "1.0″
Android:duration= "3000″/> |
| Fromalpha |
property is the transparency at the beginning of the animation |
0.0 indicates full transparency
1.0 means completely opaque
The above values take a number of float data types between 0.0-1.0 |
| Toalpha |
property is the transparency at the end of the animation |
|
Table III |
| Scale |
Gradient Dimension Stretch animation effect |
<scale
Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"
Android:fromxscale= "0.0″
Android:toxscale= "1.4″
Android:fromyscale= "0.0″
Android:toyscale= "1.4″
android:pivotx= "50%"
Android:pivoty= "50%"
Android:fillafter= "false"
Android:startoffset= "700"
Android:duration= "700″
Android:repeatcount= "10″/> |
| Fromxscale[float] Fromyscale[float] |
The scaling dimensions on the X and y coordinates when the animation starts |
0.0 means shrink to No
1.0 indicates normal no scaling
Values less than 1.0 indicate shrinkage
Values greater than 1.0 indicate magnification |
Toxscale [float]
Toyscale[float] |
When the animation ends, the scaling dimensions on the X and y coordinates |
Pivotx[float]
Pivoty[float] |
The start position of the x and Y coordinates of the animation relative to the object |
Property value Description: From 0%-100%, 50% is the midpoint position on the x or Y coordinate of the object |
|
|
|
|
|
Table IV |
| Translate |
Move animation effect on picture transition position |
<translate
Android:fromxdelta= "30″
Android:toxdelta= " -80″
Android:fromydelta= "30″
Android:toydelta= "300″
Android:duration= "2000″/> |
Fromxdelta
Toxdelta |
Position at the X coordinate of the animation, ending start |
|
Fromydelta
Toydelta |
Position on the y-coordinate for animation, ending start |
|
|
|
|
|
|
Table V |
| Rotate |
Picture Transfer rotation animation effect |
<rotate
Android:interpolator= "@android: Anim/accelerate_decelerate_interpolator"
Android:fromdegrees= "0″
Android:todegrees= "+350″
android:pivotx= "50%"
Android:pivoty= "50%"
Android:duration= "3000″/> |
| Fromdegrees |
The angle of the object at the beginning of the animation |
Description
When the angle is negative--indicates counterclockwise rotation
When the angle is positive--Indicates clockwise rotation
(Negative from--to positive: clockwise rotation)
(Negative from--to negative: counterclockwise rotation)
(Positive from--to positive: clockwise rotation)
(Positive from--to negative: counterclockwise rotation) |
| Todegrees |
property is the angle at which the object rotates at the end of the animation can be greater than 360 degrees |
Pivotx
Pivoty |
The starting bit for the x, y coordinates of the animation relative to the object |
Note: The above two attribute values are taken from the 0%-100% value
50% is the midpoint position on the x or Y coordinate of the object |
|
|
|
|
Tween animation of "Android animation" (Gradient, zoom, shift, rotate)