Tween animation is a transition process that shows rotation, gradients, moves, and scaling, that is, tweened animation. There are two ways to define Tween animations: XML form, encoding form.
XML definition Animation , complete XML according to animation definition syntax, put in/res/anim directory, file name as resource ID reference;
The encoding defines the animation , using the animation object.
XML defines animation syntax :
You must have a root element in the XML file, either in <alpha>, <scale>, <translate>, <rotate>, or <set> To manage a collection of animations made up of the preceding elements.
<set> is an animation container that manages multiple animation groups, and the corresponding Java object is animationset. It has two properties, Android:interpolator represents an interpolation resource, you can refer to the system with its own interpolation resources, you can use a custom interpolation resource, the default is a constant-speed interpolation; I'll explain the interpolation in detail later. Android:shareinterpolator represents whether multiple animations in <set> are to share the interpolation, the default value is true, that is, the shared interpolation, if set to False, then the <set> interpolation will no longer work, We'll add the interpolation to each animation.
<alpha> is a gradient animation, you can achieve Fadein and fadeout effect, and the corresponding Java object is alphaanimation. The Android:fromalpha property represents the starting alpha value, the floating-point value, the range between 0.0 and 1.0, representing transparent and completely opaque, the Android:toalpha property represents the end alpha value, the floating-point value, and the range is between 0.0 and 1.0.
<scale> Zoom animation, you can achieve dynamic control size of the effect of the corresponding Java object is scaleanimation. The Android:fromxscale property represents the initial X-direction relative to its own scaling, floating-point values, such as 1.0 for their own no change, 0.5 for the beginning of the reduction of one-fold, 2.0 for a magnification; Android: The Toxscale property represents the scaling ratio of the end in the x direction relative to itself, the floating-point value, and the Android:fromyscale property represents the scaling relative to itself in the Y direction of the start, floating point value; Android: The Toyscale property represents the scaling relative to itself in the Y direction of the end, the floating-point value, the Android:pivotx property represents the scaled axis point x coordinate, the floating-point value, the Android:pivoty property represents the scaled axis point y coordinate, the floating-point value, for both properties, If we want to represent the center of the axis point as the image, we can define two property values as 0.5 or 50%.
<translate> is a bit of moving painting that represents a horizontal, vertical displacement. The corresponding Java object is translateanimation. The Android:fromxdelta property represents the position in the starting X direction, where the Android:toxdelta represents the position in the end X direction, and the Android:fromyscale property represents the position on the starting Y direction, Android: The Toydelta property represents the position in the end Y direction, and the above four properties support three representations: floating-point numbers, num%, num%p, or, if expressed as floating-point digits, the pixel values relative to their original position; If you represent a percentage of yourself in num%, For example, a toxdelta definition of 100% represents a 1 time-fold distance in the x direction, or a percentage of the parent class component, if expressed as num%p.
<rotate> is a rotational animation, and the corresponding Java object is rotateanimation. The Android:fromdegrees property represents the starting angle, the floating-point value, the unit: degree; The Android:todegrees property represents the end angle, the floating-point value, the unit: degree, and the Android:pivotx property represents the x-coordinate of the center of rotation, Android: The Pivoty property represents the y-coordinate value of the rotation center. These two properties also have three representations, which represent the pixel relative to the left edge of itself, the num% method represents the percentage relative to its left or top edge, and the num%p represents the percentage of the left or top edge relative to the parent container.
Also, in the animation, if we add android:fillafter= "true", the animation remains in its final state after it is finished, and android:duration= "Integer" represents the duration of the animation, in millimeters.
XML Animation using code :
ImageView image = (ImageView) Findviewbyid (r.id.image);
Animation Testanim = animationutils.loadanimation (this, r.anim.test);
Image.startanimation (Testanim);