Animation
In the Android program often use animation effect, and animation effect is mainly animation to achieve, the API gives the explanation:
It contains 4 animation effects
Alphaanimation Gradient Transparency
Rotateanimation Screen Rotation
Scaleanimation Gradient Size scaling
Translateanimation Position Movement
But if you want to combine these animation effects, you need a class Animationset animation set .
Here's a simple explanation for these classes:
examples of alphaanimation :
1 New Alphaanimation (0.1f, 1.0f); 2 Alpha.setduration (+); 3 Image.startanimation (Alpha);
The transparency changes from 0.1f to 1.0f, and the event required for the change is 2s;
examples of rotateanimation :
1 New rotateanimation (0f, 360f); 2 Rotate.setduration (+); 3 Image.startanimation (rotate);
Rotates from 0 degrees to 360 degrees, duration is 2S
Examples of scaleanimation:
New Scaleanimation (0.1f, 1.0f, 0.1f, 1.0f); Scale.setduration (+); Image.startanimation (scale);
The length on the x-axis changes from 0.1 to 1.0f (view original width)
The length on the y-axis changes from 0.1 to 1.0f (view original length)
Examples of translateanimation:
1 Animation translate = New Translateanimation ( 2 animation.relative_to_self, 1.0f 3 animation.relative_to_self, 0.0f 4 animation.relative_to_self, 1.0f 5 animation.relative_to_self, 0.0f 6 translate.setduration (2000) ;
Examples of Animationset:
Animation rotate1 =Newrotateanimation (0f, 360f); Animation translate1=Newtranslateanimation (animation.relative_to_self,1.0f, Animation.relative_to_self,0.0f, Animation.relative_to_self,1.0f, Animation.relative_to_self,0.0f); Animationset Set=NewAnimationset (true); Set.addanimation (ROTATE1); Set.addanimation (TRANSLATE1); Set.setduration (2000); Image.startanimation (set);
In addition to adding animations to the code, you can also define the animation directly in the XML file, which is OK on the direct call, for example:
1 <?XML version= "1.0" encoding= "Utf-8"?> 2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android"> 3 <Alpha4 Android:fromalpha= "0.1" 5 Android:toalpha= "1.0" 6 android:duration= "$" 7 /> 8 </Set>
Program code Effects:
Each button corresponds to a different animation
Code download: Download