Android JDK provides us with 4 animation effects, namely: Alphaanimation,rotateanimation, Scaleanimation, Translateanimation. Today I would like to explain the animation effect of translateanimation. I was also in the animation of a mobile image of the project, encountered some problems. On the internet to check a lot of information, for several days. Finally understand how to use this translateanimation, recorded in this article, so that later forgotten can be consulted.
The translateanimation is a moving animation effect. It has three constructors, namely:
1.public translateanimation (Context context,attributeset attrs) Skip
2.public translateanimation (float fromxdelta, float toxdelta, float fromydelta, float toydelta)
This is one of our most common construction methods,
Float Fromxdelta: This parameter represents the difference between the point at which the animation starts and the current view x coordinate;
Float Toxdelta, which represents the difference between the point at which the animation ends and the current view x coordinate;
Float Fromydelta, which represents the difference between the starting point of the animation and the current view y-coordinate;
float Toydelta) This parameter represents the difference between the point at which the animation starts and the current view y-coordinate;
If the view is in a (x, y) point then the animation is moved from point B (X+fromxdelta, Y+fromydelta) to point C (X+toxdelta,y+toydelta).
3.public translateanimation (int fromxtype, float fromxvalue, int toxtype, float toxvalue, int fromytype, float Fromyvalu e, int toytype, float toyvalue)
Fromxtype: The first parameter is a reference to the value in the x-axis direction (Animation.absolute, Animation.relative_to_self,or animation.relative_to_parent);
Fromxvalue: The second parameter is the starting value of the first parameter type;
Toxtype,toxvalue: The third parameter and the fourth parameter are the end references and corresponding values in the x-axis direction;
The following four parameters are not explained. If you select Animation.absolute all, it is actually the second constructor.
Take the x-axis as an example to describe the relationship between references and corresponding values:
If the selection reference is Animation.absolute, then the corresponding value should be a specific coordinate value, such as 100 to 300, which refers to absolute screen pixel units
If the selection reference is animation.relative_to_self or animation.relative_to_parent refers to a relative to itself or to a parent control, the corresponding value should be interpreted as relative to itself or the number of times or percent of the parent control. The multi-test parameter is clear.
Android implementation Animation class