Reprint Please specify Source: http://blog.csdn.net/zhaokaiqiang1992
We can use the View Animation animation system to add tween animations to the View control ("Motion tweens"), and motion tweens animate by calculating some animation parameters, such as Start point, end point, size, rotation angle, and some other animation parameters.
Motion tweens can add a series of simple transformations to a view object, such as position, size, angle, or transparency. So, if you have a TextView object, you can move, rotate, or grow larger. If it has a background image, the background image will also change with the text.
Http://developer.android.com/reference/android/view/animation/package-summary.html This address provides all the classes needed for a tweened animation.
A series of animation instructions are defined as motion tweens, which can be defined using an XML file or purely code. XML files are more convenient when we want to define a layout, because they are readable, reusable, and easy to replace, compared to hard coding. So, in the following example, we'll use XML (for more information about hard-coded than XML, see Animationset classes and animation subclasses).
We can set properties to determine when we want the animation to happen, how long it lasts, and so on. The animation's transformations can occur sequentially, or they can occur at the same time. For example, we can move a textview from left to right, then rotate 180 degrees, or we can make moving animations and rotation animations happen simultaneously. Each animation transformation needs to set its own unique collection of properties (size changes need to set the start size and end size, rotation changes need to set the start angle and end angle, others are similar), but also need to set some common properties, such as the start time and duration. If we want to make a lot of transformations happen together, give them the same start time. If you want the transformation order to happen, we just need to set the start time to the total duration of the previous animation.
If we want to create an animation from an XML file, we need to create a Anim folder in the project's res directory, and the file must have only one root element, such as <alpha>,<scale>,< Translate>,<rotate>, the interpolator element, or a <set> element that contains these animated elements (which can also contain a set element). If we want to make the animation order happen, let's say we set a separate Startoffset property, like the following example.
The following XML file is from Apidemo, which is used to scale and rotate a view object at the same time.
<set android:shareinterpolator= "false" > <scale android:interpolator= "@android: Anim/accelerate_decelerat E_interpolator "android:fromxscale=" 1.0 "android:toxscale=" 1.4 "android:fromyscale=" 1.0 "Andro id:toyscale= "0.6" android:pivotx= "50%" android:pivoty= "50%" android:fillafter= "false" Android: duration= "/> <set android:interpolator=" @android: Anim/decelerate_interpolator "> <scale android:fromxscale= "1.4" android:toxscale= "0.0" android:fromyscale= "0.6" android:toyscale= "0.0" android:pivotx= "50%" android:pivoty= "50%" android:startoffset= "" "Android: Duration= "android:fillbefore=" false "/> <rotate android:fromdegrees=" 0 "an Droid:todegrees= " -45" android:toyscale= "0.0" android:pivotx= "50%" android:pivoty= "50%" Android:startoffset= "android:duration="/> </set></set>
The 0,0 point of the screen's coordinate system is above the upper-left corner of the screen, with the right x positive coordinate, and the positive coordinate of y down.
Some values, such as Pivotx, can be specified to be related to themselves or to the parent class. Make sure that the format you are using is the correct format for the effect you want, for example, 50% is 50% relative to itself, but 50 is not the same.
We can also specify a interpolator (interpolator) to determine how the transformation time changes, Android contains a few of the Interpolator sub-class, each has its own acceleration curve, such as Accelerateinterpolator, It tells the transformation to be slow at the beginning and then starts to speed up. We can set the relevant properties in the XML.
If we call the above code Hyperspace_jump.xml, we use the following code to animate a ImageView control.
ImageView spaceshipimage = (ImageView) Findviewbyid (r.id.spaceshipimage); Animation hyperspacejumpanimation = Animationutils.loadanimation (this, r.anim.hyperspace_jump); Spaceshipimage.startanimation (hyperspacejumpanimation);
as an optional way of Startanimatinon (), we can set the start time using Animation,setstarttime () and then animate with the View,setanimation ()
If you want to learn more about the XML usage and optional tag properties, see Animation Resources.
Note:
Regardless of whether your animation is moving or shrinking, the bounds of the animated view control are not automatically adjusted to fit, and even so, the animation will still be drawn out, in time beyond the boundaries and will not be cut. However, if the animation is outside the scope of the parent view, the excess will be cut.
Original address: http://developer.android.com/guide/topics/graphics/view-animation.html
"Android Interface Implementation" View Animation usage Introduction