· Property Animation andViewthe difference between animations
The View animation system provides the ability to animate only the view object, so if you want to animate a non- view object, you'll implement the code yourself. The View animation system is also actually forced to animate only a few properties of the view , such as zooming and rotating, rather than the background color.
Another disadvantage of view animation is that it modifies only the view's drawing position, not the actual location of the view. For example, if you animate a move through the screen, the button's drawing position is correct, but the actual position you can click on it doesn't change, so you have to implement your own logic to handle it.
When using the property animation system, this restriction is completely dismissed, and you can animate any property of any object (view or non-view) and the object itself is actually modified. And the property animation system itself has more strength to support animation. At the top, you assign animations to properties to animate, such as color, position, or size, and then define animation parameters such as interpolation algorithms and synchronization of multiple animations.
However, the View animation system requires only a small amount of time to set and does not require too much code. If the view animation is exactly what you need, or if you can work as you want in your old code, then you don't need to use the property animation system. It is also possible to use both of these animation systems in some cases.
· ApiOverview
You can find most of the property animation system APIs in android.animation . Because the view animation system has defined many interpolation algorithms in android.view.animation , you can also use them in the property animation system. The main composition of the property animation system is described in the following table.
The Animator class provides the basis for creating animations. You should generally not use this class directly, as it provides only the least amount of functionality. The following subclasses are derived from Animator .
Table 1. Animators
class |
Description |
valueanimator |
Property. It calculates the value of the property to animate. It has the core function of all computed animation values, which contains the time information for each animation, whether to repeat it, to receive the listener for the update event, and to set how the custom type is calculated. Animate one property to do two: calculate the value of the animation and set these values to the object or property. valueanimator is not responsible for the second, so you must listen for valueanimator updates to the values and then press your logic to modify the objects you want to animate. |
objectanimator |
 VALUEANIMATOR&N A subclass of BSP. Allows you to set the properties of the target object and object to animate. This class updates the property when it calculates the new value of the animation. Most of the time you should choose to use OBJECTANIMATOR&NBSP, because it's easier to use it to manipulate objects ' animations. However, at some point you may want to use valueanimator directly, because objectanimator has many limitations, such as the need for an object to have a specific operator method. |
Animatorset |
Provides a mechanism for controlling animation relationships in animation groups. You can set multiple animations to play together, play separately, or delay playback. |
Evaluator tells the property animation system how to calculate the value of an attribute. They calculate the value of the animation based on the time information provided by the Animator class, the start value of the animation, and the ending value. The property animation system provides the following evaluator:
Table 2. Evaluator!
class/interface |
Description |
intevaluator |
Calculates the default int for evaluator-type properties. |
floatevaluator |
Compute float evaluator |
argbevaluator |
Calculate the color properties represented by hexadecimal values The default evaluator . |
typeevaluator |
A interface that allows you to create your own evaluator 。 If you want to animate the properties of an object that is not Int, float color, you must implement typeevaluator Interface to define how to calculate an animated value for an object property. If you want to change the default behavior for handling int, float, and color properties, you can also specify custom typeevaluator for them. |
The time Interpolator defines how the time function calculates the value of the animation. For example, you can specify that the animation process is linear, which means that the animation is moving evenly, or specifying a non-linear time, such as accelerating at the beginning and slowing down at the end. Table 3 describes the interpolator in the android.view.animation . If the existing interpolator does not satisfy you, you can implement the interface Timeinterpolator to create your own interpolator.
Table 3. Our Interpolator
Class/interface |
Describe |
Acceleratedecelerateinterpolator |
The middle of the fast two slow interpolator. |
Accelerateinterpolator |
An always-accelerating interpolator. |
Anticipateinterpolator |
The first step backwards and forwards the interpolator. |
Anticipateovershootinterpolator |
The interpolator that goes back, then forwards, exceeds the end value and then returns to the end value. |
Bounceinterpolator |
The last jump of the interpolator. |
Cycleinterpolator |
The interpolator that repeats the loop playback. |
Decelerateinterpolator |
The interpolator that has been slowing down. |
Linearinterpolator |
A constant-speed playback of the interpolator. |
Overshootinterpolator |
The interpolator that first moves forward until the end value is exceeded and then returns to the start value. |
Timeinterpolator |
Allows you to implement your own Interpolator interface. |
Previous: Android animation detailed two-attribute animation principle
Android Animation three animation API overview