The file name is myanimation. XML, which is located in the Res/anim folder:
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Set xmlns: Android = "http://schemas.android.com/apk/res/android">
- <! --
- Tween animation: animated effects are generated by constantly performing image transformations (translation, scaling, and rotation) on objects in the scenario.
- ALPHA: gradient transparency animation effect
- Scale: gradient scaling animation effect
- Translate: animation effect for moving the position of the screen
- Rotate: animation effect of screen Rotation
- Tween animation common attribute [type] Function
- The duration [long] attribute is the animation duration in milliseconds.
- When fillafter [Boolean] is set to true, the animation is applied after the animation ends.
- When fillbefore [Boolean] is set to true, the animation is applied before the animation starts.
- Interpolator specifies an animation plug-in that has some common plug-ins.
- Accelerate_decelerate_interpolator
- Accelerator-slowdown animation inserter
- Accelerate_interpolator
- Acceleration-animation insertor
- Decelerate_interpolator
- Slowdown-animation inserter
- Other animation Effects
- Repeatcount [int] Number of animation repetitions
- Repeatmode [int] defines repeated behavior 1: Start again 2: plays backward
- The interval between the startoffset [long] animations, starting from the time when the animation was stopped.
- Zadjustment [int] defines the change of Z order of the animation 0: Keep Z order unchanged
- 1: Keep at the top
- -1: Keep at the bottom layer
- -->
- <! --
- Transparent animation control
- -->
- <Alpha
- Android: fromalphi = "0.1"
- Android: toalpha = "1.0"
- Android: duration= "3000"
- />
- <! -- Scale up and down the animation effect
- Attribute: interpolator specifies an animation plug-in.
- There are three types of animation inserts:
- Accelerate_decelerate_interpolator acceleration-Deceleration animation inserter
- Accelerate_interpolator acceleration-animation insertor
- Decelerate_interpolator deceleration-animation insertor
- Other animation Effects
- The fromxscale attribute is the scaling size on the X coordinate when the animation starts.
- The toxscale attribute is the scaling size on the X coordinate when the animation ends.
- The fromyscale attribute is the scaling size on the Y coordinate at the start of the animation.
- The toyscale attribute is the scaling size on the Y coordinate when the animation ends.
- Note:
- The preceding four property values
- 0.0 indicates shrinking to none
- 1.0 indicates normal scaling-free
- A value smaller than 1.0 indicates contraction.
- Value greater than 1.0 indicates Amplification
- The ready TX attribute is the starting position of the animation relative to the X coordinate of the object.
- The ready ty attribute is the starting position of the animation relative to the Y coordinate of the object.
- Note:
- The preceding two attribute values are from 0% to 100%.
- 50% indicates the point position on the X or Y coordinate of the object.
- Long integer value:
- The duration attribute is the animation duration.
- Description: The time is in milliseconds.
- Boolean value:
- When the fillafter attribute is set to true, the animation is applied after the animation ends.
- -->
- <Scale
- Android: interpolator = "@ Android: anim/accelerate_decelerate_interpolator"
- Android: repeatcount = "1"
- Android: fromxscale = "0.5"
- Android: fromyscale = "0.5"
- Android: toxscale = "1.4"
- Android: toyscale = "1.4"
- Android: Required Tx = "50%"
- Android: Ty = "50%"
- Android: fillafter = "false"
- Android: duration= "3000"
- />
- <! --
- Animated effect translate
- Fromxdelta toxdelta is the position on the X coordinate at the animation end start.
- Fromydelta toydelta is the position on the Y coordinate when the animation ends.
- -->
-
- <Translate
- Android: repeatcount = "2"
- Android: fromxdelta = "-30"
- Android: fromydelta = "-30"
- Android: toxdelta = "-80"
- Android: toydelta = "200"
- Android: duration= "3000"
- />
- <! --
- Screen transfer rotation animation effect rotate
- Fromdegrees indicates the object angle when the animation starts.
- If the angle is negative, it indicates clockwise rotation.
- If the angle is positive, it indicates clockwise rotation.
- (Negative from -- to positive: clockwise rotation)
- (Negative from -- to negative: counter-clockwise rotation)
- (Positive from -- to positive: clockwise rotation)
- (Positive from -- to negative: clockwise rotation)
- The todegrees attribute indicates that the Rotation Angle of an object can be greater than 360 degrees when the animation ends.
- Pivotx
- Ty indicates the starting position of the animation relative to the X and Y coordinates of the object. The preceding two attribute values are from 0% to 100%.
- 50% indicates the point position on the X or Y coordinate of the object.
- -->
- <Rotate
- Android: interpolator = "@ Android: anim/accelerate_interpolator"
- Android: repeatcount = "2"
- Android: fromdegrees = "0"
- Android: todegrees = "+ 270"
- Android: Required Tx = "50%"
- Android: Ty = "50%"
- Android: duration= "3000"
- />
- </Set>
Usage: add the animation definition to a textview. The work to be done is simple:
- Animation mAnimation ;
- mAnimation = AnimationUtils.loadAnimation(this, R.anim.anim);
- TextView text = (TextView)findViewById(R.id.textview00);
- text.setAnimation(mAnimation);
Note that you must use the START () method of animationdrawable to start the animation. Whether or not the animation is complete, you must first call its stop () method to start the animation for the second time () method to start the animation again.