On the implementation of animations, Android provides animation, with two animation (animated) modes
1. Tween Animation: It is a kind of gradient animation to animate the object in the scene by constantly making image transform (translation, zooming, rotation);
2. Frame Animation: Sequential playback of pre-done images, is a picture conversion animation.
Type of Animation:
Android animation is made up of four different types
In the XML file:
|--alpha Gradient transparency Change effect
|--scale Gradient Dimension Stretch animation effect
|--translate picture Conversion position Move animation effect
|--rotate Picture Transfer rotation animation effect
The related classes defined in the Android source code can be used to get and manipulate related properties.
Animation
|--alphaanimation Gradient Transparency Animation effect
|--scaleanimation Gradient Dimension Stretch animation effect
|--translateanimation picture Conversion position Move animation effect
|--rotateanimation Picture Transfer rotation animation effect
Here is a specific example of a picture rotation
1. First define a picture in the XML file
<imageview
Android:layout_width= "60DP"
android:layout_height= "60DP"
Android:id = "@+id/image_rotate"
android:src= "@drawable/xuanyi"
android:layout_gravity= "Center"/>
2. Create a new XML file define rotate rotation effect
Create a new folder named Anim under Res and create a new Rotate.xml file under this folder
<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
<rotate
Android:fromdegrees = "0"
android:todegrees= "359"
Android:duration= "400"
Android:repeatcount= "-1"
android:pivotx= "50%"
Android:pivoty= "50%">
<!--android:fromdegrees start Angle--
<!--android:todegrees end angle degrees, negative numbers are counterclockwise, positive numbers are clockwise--and
<!--android:duration represents the amount of time it takes to rotate from android:fromdegrees to android:todegrees in milliseconds. can be used to calculate speed. -
<!--android:repeatcount Repeat number, default is 0, must be int, can be 1 means no stop--
<!--the x-coordinate of the Android:pivotx rotation center--
<!--the y-coordinate of the Ndroid:pivoty rotation center--
<!--other resources can go to the API to find
</rotate>
</set>
3, establish an object of animation class
Load the XML file with Animationutils, which returns a animation object
Animation Animademo = Animationutils.loadanimation (this, r.anim.rotate);
/*an Interpolator defines the change of a animation.
This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated, etc.
Interpolator is an interface that defines the speed at which animations change, with 5 implementation classes, each of which is acceleratedecelerateinterpolator,
Accelerateinterpolator, Cycleinterpolator, Decelerateinterpolator, Linearinterpolator
Linearinterpolator for constant speed effect, accelerateinterpolator for acceleration effect, decelerateinterpolator for deceleration effect
Here is the effect of setting a uniform speed
Interpolator represents the rate of change, but not the speed of operation. An interpolation property that sets the animation effect to acceleration, deceleration, repetition, bounce, and so on. The default is start and end slow middle fast,
*/
Linearinterpolator lin = new Linearinterpolator ();
Set the speed of the animation, passing in a rate of speed change
Animademo.setinterpolator (Lin);
4, in the Android code to create a picture to add animation
Find a picture by ID
Imagerotate = (ImageView) Findviewbyid (r.id.image_rotate);
A stunt (animation) to rotate a picture
Imagerotate.startanimation (Animademos);
5. Stop Animation
Animademo.clearanimation ();
Resources:
http://blog.csdn.net/mengzhengjie/article/details/9674845
Http://www.cnblogs.com/feisky/archive/2010/01/11/1644482.html
Android Animation Learning