In Android development, the appropriate animation effect can make the interaction more interesting and suggestive, so in the development of Android, animation design is an indispensable link. The animation that comes with the Android frame can be divided into transform animation, frame animation, layout animation and property animation, one by one slowly. Learn to transform animations first.
There are four types of transform animations: alphaanimation (transparency animation), scaleanimation (zoom animation), Translateanimation (panning animation), rotateanimation (rotate animation). They are all subclasses of the animation class, and naturally inherit its methods, such as Setduration ()-Set animation time, setstartoffset--set animation start delay time, and so on.
The most basic usage is:
ImageView animationexample; Animation Animation; =// Transparency from 0.2 to 1.0 new alphaanimation (0.2f,1.0f); // The total length of the animation process is 2 seconds animation.setduration (+); // The animation starts with a delay of 1 seconds (Animation.setstartoffset); // set the animation for this imageview Animationexample.setanimation (animation);
Just 7 lines of code above, you can make a picture from translucent to slowly become opaque animation.
However, sometimes we don't want animations to be so simple that we might want to have multiple animations at the same time. Android provides us with a handy class animationset that we can use to easily combine multiple animations together. Let's change the above code to this.
ImageView animationexample; Animationset Animationset; Animation Animation; Animationexample=(ImageView) Findviewbyid (r.id.animation_example);
Animationset = new Animationset (true);//transparency from 0.2 to 1.0Animation =NewAlphaanimation (0.2f,1.0f);//Animation process 2 seconds totalAnimation.setduration (2000);//1 seconds delay at start of animationAnimation.setstartoffset (1000); Animationset.addanimation (animation);//size from 0.2,0.2 wide to 1.0, 1.0 wide HighAnimation =NewScaleanimation (0.2f,1.0f,0.2f,1.0f);//Animation process 2 seconds totalAnimation.setduration (2000);//1 seconds delay at start of animationAnimation.setstartoffset (1000); Animationset.addanimation (animation); //set the animation for this imageviewAnimationexample.setanimation (Animationset);
As shown in the code above, we have two animations, one is to change the transparency from 0.2 to 1, one is to size the picture from 0.2 to 1, and their duration and start delay time are the same. At this point, we add two animation through animationset.addanimation () This method to Animationset ,animationset itself is also a Animation subclass, and in the end, we just need to make the picture perform the animation in Animationset.
Here, our icons contain two animations at the same time. Today is a hasty day, continue to fill this hole tomorrow.
A tentative study of animation (I.)