[1] Transparent
//Click the button to achieve IV transparency effect animation Public voidClick1 (View v) {//1.0 means completely opaque 0.0 means completely transparentAlphaanimation AA =NewAlphaanimation (1.0f, 0.0f); Aa.setduration (2000);//set time for animation executionAa.setrepeatcount (1);//set number of repetitionsAa.setrepeatmode (Animation.reverse);//set the mode of animation execution//IV Start Animationiv.startanimation (AA); }
[2] Rotation
//Click the button implementation IV to perform a rotation animation Public voidClick2 (View v) {//fromdegrees Start angle todegrees End Angle//rotateanimation ra = new Rotateanimation (0, 360); Rotateanimation RA =NewRotateanimation (0, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Ra.setduration (2000);//set time for animation executionRa.setrepeatcount (1);//set number of repetitionsRa.setrepeatmode (Animation.reverse);//set the mode of animation execution//IV Start Animationiv.startanimation (RA); }
[3] Scaling
// Click the button to make a zoom animation public void Click3 (View v) {Scaleanima tion sa = new scaleanimation (1.0f,2.0f, 1.0f, 2.0f, animation.relative_to _self, 0.5f, animation.relative_to_self, 0.5f); Sa.setduration ( 2000); // Set the time of the animation execution Sa.setrepeatcount (1); // Set the number of repetitions sa.setrepeatmode (animation.reverse); // Set the mode of animation execution // iv start animation Iv.startanimation (SA); }
[4 "displacement
public void Click4 (View v) { new translateanimation ( Animation.relative_to_parent, 0, animation.relative_to_parent, 0, animation.relative_to_parent, 0, Animation.relative_to_parent, 0.2f); Ta.setduration (// set time for animation execution ta.setfillafter (true); When the animation ends, the animation stops at the end position // start animation iv.startanimation (TA); }
//Animations Fly together Public voidClick5 (View v) {Animationset set=NewAnimationset (false); //Transparent animationsAlphaanimation AA =NewAlphaanimation (1.0f, 0.0f); Aa.setduration (2000);//set time for animation executionAa.setrepeatcount (1);//set number of repetitionsAa.setrepeatmode (Animation.reverse);//set the mode of animation execution//Rotate AnimationRotateanimation RA =NewRotateanimation (0, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Ra.setduration (2000);//set time for animation executionRa.setrepeatcount (1);//set number of repetitionsRa.setrepeatmode (Animation.reverse);//set the mode of animation execution//ZoomScaleanimation SA =NewScaleanimation (1.0f,2.0f, 1.0f, 2.0f, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Sa.setduration (2000);//set time for animation executionSa.setrepeatcount (1);//set number of repetitionsSa.setrepeatmode (Animation.reverse);//set the mode of animation executiontranslateanimation ta=NewTranslateanimation (animation.relative_to_parent, 0, animation.relative_to_parent, 0, Animation.relative_to_parent, 0, Animation.relative_to_parent, 0.2f); Ta.setduration (2000);//set time for animation executionTa.setfillafter (true);//The animation stops at the end position when the animation ends//Add animationsset.addanimation (AA); Set.addanimation (RA); Set.addanimation (SA); Set.addanimation (TA); //The last step is to remember to perform the animationiv.startanimation (set); }
View animations in Android