ValueAnimator has learned some common methods during the learning process. You can take notes and note the following:
When I first read the animation examples of apidemo of 4.0, I first came into contact with ObjectAnimator. Therefore, the concept of ValueAnimator, as its parent class, should be similar to the animation class. It is found that ValueAnimator does not directly define operation objects like ObjectAnimator, and even suspects that animation can be controlled without objects ). Now, I understand that ValueAnimator is a timer designed for animation optimization. That's right, it's a simple timing engine for running animations written on the official SDK ). It is easier to use a timer to understand that no object is available. Because after an object is associated, it is naturally an animation.
First, list the simple and intuitive methods you can see:
ValueAnimator. setDuration (int) specifies the animation duration, in ms.
ValueAnimator. setTaget (Object) sets the animation Object, such as ImageView
ValueAnimator. clone () copies an identical animation. Generally, it works with setTarget to modify the associated object of the animation to be copied.
1. ValueAnimator. addUpdateListener (class that implements ValueAnimator. AnimatorUpdateListener)
If this sentence is not added, the animation object cannot be played when ValueAnimator or AnimatorSet. start is changed.
Why? The following figure shows the comparison mechanism:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/10251SQ7-0.png "title =" 2011120119191590.png"/>
ValueAnimator will automatically getAnimatedValue () on time to get the value of the property to be changed, and then copy it to the property so that the system will automatically update the corresponding property of the animation object to refresh the display.
It should be noted that if all animations use the same UpdateListener object, as long as one of the animations has an addUpdateListener, all animations use its Duration length to update the playback content of their corresponding animation time periods. Very round # @ U &~
For example, animation A \ B, A from x = 0-> x = 10, duration: 1000 B from x = 0-> x = 9, duration: 3000 (linear animation). addUpdateListener, B does not. A \ B: the animation takes only 1 second. A ranges from x = 0-> x = 10, B ranges from x = 0-> x = 3 to 1/3 of the animation time.
2. ValueAnimator. ofFloat (Float... Value)
This method mainly records my understanding of Variable Parameter Float... Value. Generally, it is commonly used to set (0f, 1f), which means that the starting value of the animation object's attribute value ranges from 0 ~ 1. Simple and intuitive understanding:
Corresponding ofFloat (0f, 40f). setDuration (40), no new definitions of TimeInterpolator and TypeEvaluator
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/10251SM6-1.png "title =" 2011120119185844.png"/>
3. ValueAnimator. setInterpolator (inherits the Interpolator class)
This method sets the Interpolator for the animation object (I translated it as the compensation controller). When I used Flash animation or early Android Tween animation, I used the word "compensation" for translation, or it can be understood as the animation change rate. I can't tell the specific understanding, and I don't want to translate the SDK directly. It's too boring. Here we will talk about the methods that Interpolator needs to implement interfaces for customization.
Here is a simple class for implementing the Interpolator interface:
Import android. view. animation. Interpolator;
Public class MyInterpolator implements Interpolator {
Private float mFactor;
Private int I;
Public MyInterpolator (int I ){
This. I = I;
}
@ Override
Public float getInterpolation (float input ){
Switch (I ){
Case 1: mFactor = input;
Break;
Case 2: mFactor = input * input;
Break;
}
Return mFactor;
}
}
When the initial variable is 1, mFactor = input is a linear function, and the "Change Rate" is constant.
When the initial variable is 2, mFactor = input * input is a curve function, and the "Change Rate" is cubic.
Note that the input value is 0.0f ~ Floating point type of 1.0f
From the above perspective, a custom Interpolator is a linear function variable that is automatically output by the system based on the animation time/total animation duration, we cannot change it. However, you can implement a custom function in the override getInterpolation method, and the function value required for return can be.
4. AnimatorSet. playTogether (Animator... obj)
Play several animations at the same time. You need to note that in the AnimatorSet. when starting (), not all animations are reset and played again. Only the first animation is reset to the initial state and then played again. Other animations are ignored before the first animation is completed. start () can be triggered to play again after the first animation has been played.