in Android development, animation is used to create effects on controls. Most controls can use this class, which contains 4 basic actions, namelyMoving,Rotate,fade in and fade,Zoom.
There are two ways to use animation:
One way: Create, set, and start animations in code (move translateanimation/rotation rotateanimation/fade alphaanimation/Zoom scaleanimation ), the advantage is that it is convenient to debug the program effect;
Mode two: In the XML to set the properties of the control, the advantage is that the code reusability is relatively high, the disadvantage is not convenient debugging.
Here's an example of how Code creation works:
Before we start the example we have two very important reference standards:animation.relative_to_self (relative to itself), Animation. Relative_to_parent (relative to the parent control (container)).
1,ImageView control from completely transparent to completely opaque change, the duration is 0.2s;
private void Tovisibleanim (view view) {alphaanimation alphaanimation = new Alphaanimation (0.0f, 1.0f); Alphaanimation.setduration ($); View.startanimation (alphaanimation);}
2,ImageView control from the original size dimension along its own size center gradually scaled to 0, the duration is 0.2s;
private void Tohideanim (view view) {scaleanimation scaleanimation = new Scaleanimation (1.0f, 0.0f, 1.0f, 0.0f, ANIMATION.R Elative_to_self, 0.5f, Animation.relative_to_self, 0.5f); scaleanimation.setduration; View.startanimation ( scaleanimation);}
3, imageview control The rotates 90 degrees at the center of itself, with a duration of 0.2S;
private void Rotateanim (view view) {view.setvisibility (view.visible); Rotateanimation rotateanimation = new Rotateanimation (0, Animation.relative_to_self, 0.5f, animation.relative_to_ Self, 0.5f); rotateanimation.setduration (+); view.startanimation (rotateanimation);}
4, imageview control The slides horizontally from the right end of its position to the left, and the duration is 0.2S;
private void Showscrollanim (view view) {view.setvisibility (view.visible); Translateanimation mshowaction = new Translateanimation (animation.relative_to_self, 1.0f, animation.relative_to_self , 0.0f, Animation.relative_to_self, 0.0f,animation.relative_to_self, 0.0f); mshowaction.setduration (200); View.startanimation (mshowaction);}
5. The image control moves horizontally from the leftmost end of its position to the right to hide the animation, duration 0.2s
private void Hiddenscrollanim (LinearLayout view) {view.setvisibility (view.gone); Translateanimation mhiddenaction = new Translateanimation (animation.relative_to_self, 0.0f, Animation.RELATIVE_TO_ self,1.0f, Animation.relative_to_self, 0.0f,animation.relative_to_self, 0.0f); mhiddenaction.setduration (200); View.startanimation (mhiddenaction);}
android--uses animation.relative_to_self to personalize animations