There are many animation effects in Android, including ViewAnimator, frame-by-frame animation and complementary animation. Today, let's take a look at the four Basics of the animation.
I. fade in and fade out Alpha
The effect of Fade-in and fade-out is different in the transparency of the screen at different times.
Specific implementation:
1) instantiate the AnimationSet object
// Instantiate the AnimationSet object AnimationSet animationSet = new AnimationSet (true ); |
2) instantiate the AlphaAnimation object
// Instantiate the AlphaAnimation object. The parameter is (transparency at the beginning, transparency at the end) // 1 indicates completely opaque, and 0 indicates completely transparent AlphaAnimation zAnimation = new AlphaAnimation (1, 0 ); |
3) set the animation duration
// Set the animation duration zAnimation. setDuration (3000 ); |
4) Add the AlphaAnimation object to the AnimationSet.
// Add the AlphaAnimation object to the AnimationSet animationSet. addAnimation (zAnimation ); |
5) Enable Animation
// Enable the animation iv. startAnimation (animationSet) on the iv ); |
Ii. Rotating Rotate
The animation effect displayed by rotation is the animation effect of the image with the rotation angle setting.
Specific implementation:
1) instantiate the AnimationSet object
// Instantiate the AnimationSet object AnimationSet animationSet = new AnimationSet (true ); |
2) instantiate the RotateAnimation object
// Instantiate the RotateAnimation object. The parameter is the starting angle and Rotation Angle of the rotation. The type of the rotation center is based on your own). 0.5f indicates the center in the x or y direction) rotateAnimation animation = new RotateAnimation (0,360, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, (float) 0.5 ); |
3) set the animation duration
// Set the animation execution time to animation. setDuration (3000 ); |
4) Add the RotateAnimation object to the AnimationSet.
// Add the animation to the AnimationSet. addAnimation (animation ); |
5) Enable Animation
// Load the animation to the control and enable the animation iv. startAnimation (animationSet ); |
Iii. Scale
The effect of zooming is as follows: the video is played with the animation and different sizes and proportions are displayed.
Specific implementation:
1) instantiate the AnimationSet object
// Instantiate the AnimationSet object AnimationSet animationSet = new AnimationSet (true ); |
2) instantiate the ScaleAnimation object
// Parameter: the last four parameters indicate that the center of the scaling is the center of the image. // the first four parameters indicate that when the animation is executed, first, the image size changes from F to the position represented by 1. If 1 is changed to 2 //, the image size changes from half to 2 times. // Instantiate ScaleAnimation object ScaleAnimation animation = new ScaleAnimation (0.5f, 2, 0.5f, 2, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f ); |
3) set the animation duration
// Set the animation duration animation. setDuration (3000 ); |
4) Add the ScaleAnimation object to the AnimationSet.
// Indicates the notification state when the animation ends. By default, the notification state is returned to the original initial state. However, after the animation ends, the animation remains at the animation end moment. setFillAfter (true); // Add the ScaleAnimation object to the AnimationSet. addAnimation (animation ); |
5) Enable Animation
// Enable animation iv. startAnimation (animationSet ); |
4. Move Translate
The effect of moving is as follows: the screen moves on the screen as the animation is played.
Specific implementation:
1) instantiate the AnimationSet object
// Instantiate the AnimationSet object AnimationSet animationSet = new AnimationSet (true ); |
2) instantiate the TranslateAnimation object
// Instantiate the TranslateAnimation object // parameter: 1 3 5 7 indicates the reference point type, which is the moving value of the image itself // parameter: 2 4 6 8, 1 indicates the width and height of the image. 0 indicates that the image is moved from the upper left corner of the image to TranslateAnimation animation = new TranslateAnimation (Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 1, Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 1 ); |
3) set the animation duration
// Set the animation duration animation. setDuration (3000 ); |
4) Add the TranslateAnimation object to the AnimationSet.
// Add TranslateAnimation to the AnimationSet object. addAnimation (animation ); |
5) Enable Animation
// Enable animation iv. startAnimation (animationSet ); |
The above four animations are all implemented in the click event on the ImageView control in the main interface. Because the results are not well captured, you can test them on your own. More results must be implemented after planning... Fuel 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/10002L611-0.gif "/>
This article is from the "Schindler" blog, please be sure to keep this source http://cinderella7.blog.51cto.com/7607653/1294055