Animtion of android simple animation
Android's simple animation effects include the Animtion class. 1. Implement the animation effect in XML; 2. Implement the animation effect in java code.
Animation-related attributes <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Cjx0YWJsZSBib3JkZXI9 "1" width = "1200" cellspacing = "1" cellpadding = "1"> Table 1: SET attributesNameAttributeRemarksAndroid: Movie interpolatorWhether to share the inserterWhen shared, each of the four subnodes uses an insertor.Android: interpolatorSpecifies an animation insertor.Use System ResourcesAndroid: fillEnabled
If it is set to true, both fillAfter and fillBefroe will be true, and the fillBefore and fillAfter attributes will be ignored.Android: fillAfterWhether the animation is applied after the animation endsBooleanAndroid: fillBeforeWhether the animation is applied before the animation starts.BooleanAndroid: repeatModeRepeat mode"Restart" = start from scratch or "reverse" = start from the endAndroid: repeatCountRepeated timesInteger-1 is an infinite loopAndroid: durationAnimation durationIntegerAndroid: startOffsetAnimation time interval (animation duration before execution)LongAndroid: zAdjustmentDefine the z order Transformation of an animation[Normal] or [top] or [bottom]Android: detachWallpaperUnknownBoolean
Here we will explain in detail the attributes of the android: interpolator animation plug-in (the embodiment of the animation speed effect ).
1. @ android: anim/accelerate_decelerate_interpolator: acceleration before deceleration
2. @ android: anim/accelerate_interpolator: acceleration
3. @ android: anim/decelerate_interpolator: deceleration
4. @ android: anim/anticipate_interpolator: first move a point in the opposite direction of the animation and then move the track along the set animation, as shown in.
5. anticipate_overshoot_interpolator: first move a point to the opposite direction of the animation, then move it to the end point in the set direction, and then move it back to the final position. For example:
6. @ android: anim/bounce_interpolator: After an animation is moved to the last position, it will have a rebound effect several times, and the animation will be stopped at the specified position.
7. @ android: anim/cycle_interpolator: animation cycle movement.
8. @ android: anim/linear_interpolator: the animation moves at a constant speed.
9. @ android: anim/overshoot_interpolator: the animation moves in the opposite direction to the last position.
| Interpolator object |
Resource ID |
Function |
| AccelerateDecelerateInterpolator |
@ Android: anim/accelerate_decelerate_interpolator |
Acceleration before deceleration |
| AccelerateInterpolator |
@ Android: anim/accelerate_interpolator |
Acceleration |
| AnticipateInterpolator |
@ Android: anim/anticipate_interpolator |
Let's take a small step back and then speed up. |
| AnticipateOvershootInterpolator |
@ Android: anim/anticipate_overshoot_interpolator |
On the basis of the above, a small step beyond the end and then return to the end |
| BounceInterpolator |
@ Android: anim/bounce_interpolator |
Final fl Effect |
| CycleInterpolator |
@ Android: anim/cycle_interpolator |
Periodic exercise |
| DecelerateInterpolator |
@ Android: anim/decelerate_interpolator |
Deceleration |
| LinearInterpolator |
@ Android: anim/linear_interpolator |
Uniform speed |
| OvershootInterpolator |
@ Android: anim/overshoot_interpolator |
Quickly reach the destination and return to the destination after a small step |
For a link to modify the attributes of the animation insertor, click the open link.
Table 2: alpha
| Name |
Attribute |
Remarks |
| Android: toAlpha |
Transparency at animation end |
Float [0, 1] 0 indicates completely transparent 1 indicates completely opaque |
| Android: duration |
Animation duration |
Integer |
| Android: fromAlpha |
Transparency at the beginning of the animation |
Float [0, 1] 0 indicates completely transparent 1 indicates completely opaque |
| |
|
|
Table 3: SCALE
| Name |
Attribute |
Remarks |
| Android: fromXScale |
Scaling size on the X coordinate at the start of the animation |
Float, 0.0 indicates shrinking to none, 1.0 indicates normal scaling, less than 1 indicates shrinking, greater than 1 indicates enlarging |
| Android: toXScale |
Scaling size on X coordinate at animation end |
Same as above |
| Android: fromYScale |
Scaling size on Y coordinate at animation start |
Same as above |
| Android: toYScale |
Scaling size on Y coordinate at animation end |
Same as above |
| Android: strongtx |
Start position of the animation relative to X of the object |
[0%, 100%], 50% indicates the center |
| Android: policty |
Start position of the animation relative to Y of the object |
0%, 100%], 50% indicates the center |
| Android: duration |
Same as set |
Same as set |
| |
|
|
Table 4: TRANSLATE
| Name |
Attribute |
Remarks |
| Android: fromXDelta |
Position on X coordinate at animation start |
By default, integer takes itself as the reference object. |
| Android: toXDelta |
Position on X coordinate at animation end |
By default, integer takes itself as the reference object. |
| Android: fromYDelta |
Position on Y coordinate at animation start |
By default, integer takes itself as the reference object. |
| Android: toYDelta |
Position on Y coordinate at animation end |
By default, integer takes itself as the reference object. |
| |
|
|
Table 5: ROTATE
| Name |
Attribute |
Remarks |
| Android: fromDegrees |
The angle of the object at the beginning of the animation. |
Negative: clockwise rotation, positive: clockwise rotation |
| Android: toDegrees |
The angle of the object at the end of the animation (up to 360 degrees) |
Same as above |
| Android: strongtx |
Start position of the animation relative to X of the object |
[0%, 100%], 50% indicates the center |
| Android: policty |
Start position of the animation relative to Y of the object |
[0%, 100%], 50% indicates the center |
| |
|
1. Implement alpha in. XML:
Note: If you need to set the animation to android: fillAfter = "true"
Android: fillBefore = "false" must be Which is valid only. For example, the valid settings are as follows:
Then the above animation stays on the last frame.
Ii. Code Implementation alpha
Animation anim = new AlphaAnimation(0f, 1.0f);anim.setDuration(2000);anim.setRepeatCount(Animation.INFINITE);anim.setRepeatMode(Animation.RESTART);
Iii. scale with XML
>
Android: equalty = "50.0%" android: repeatCount = "3" android: repeatMode = "reverse" android: toXScale = "1.0" android: toYScale = "1.0"/>
Iv. Code Implementation scale
Animation anim1 = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, 0.5f, 0.5f);anim1.setDuration(2000);anim1.setRepeatCount(3);anim1.setRepeatMode(Animation.REVERSE);anim1.setInterpolator(this, interpolator.accelerate_decelerate);anim1.setFillAfter(true);
V. Implement stranslate in XML
Code 6: Implement Stranslate
Animation animTranlate = new TranslateAnimation(0, 0, 0, 400);animTranlate.setDuration(2000);animTranlate.setFillAfter(true);animTranlate.setInterpolator(this, interpolator.bounce);text.startAnimation(animTranlate);
VII. Implement rotate in XML
/>
8. Code Implementation rotate
Animation animRotate = new RotateAnimation (0f, 360f, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f); animRotate. setDuration (1, 2000); animRotate. setInterpolator (this, interpolator. bounce); animRotate. setFillAfter (true); animRotate. setStartOffset (2000); // specifies the animation duration text before execution. startAnimation (animRotate );
9. Implementation of composite Animation
10. Code-based composite Animation
Animation anim1 = new ScaleAnimation(0.5f, 1.0f, 0.5f, 1.0f, 0.5f, 0.5f);anim1.setDuration(2000);anim1.setRepeatCount(3);anim1.setRepeatMode(Animation.REVERSE);anim1.setInterpolator(this, interpolator.accelerate_decelerate);anim1.setFillAfter(true);// text.setAnimation(anim1);Animation animTranlate = new TranslateAnimation(0, 0, 0, 400);animTranlate.setDuration(2000);animTranlate.setFillAfter(true);animTranlate.setInterpolator(this, interpolator.bounce);// text.startAnimation(animTranlate);Animation animRotate = new RotateAnimation(0f, 360f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);animRotate.setDuration(2000);animRotate.setInterpolator(this, interpolator.bounce);animRotate.setFillAfter(true);// text.startAnimation(animRotate);AnimationSet animationSet = new AnimationSet(true);animationSet.addAnimation(animRotate);animationSet.addAnimation(animTranlate);animationSet.addAnimation(anim1);text.startAnimation(animationSet);
End!