ObjectAnimatorhtml
1.This class updates the property accordingly android
2.much easierweb
3.has a few more restrictionsapp
4. you no longer need to implement theValueAnimator.AnimatorUpdateListener
, because the animated property updates automaticallyless
1.you must listen for updates to values calculated by the ValueAnimator
and modify the objects that you want to animate with your own logicui
2.computes the values for the property to be animatedthis
3. It has all of the core functionality that calculates animation values and contains the timing details of each animation,spa
There are two pieces to animating properties: calculating the animated values and setting those values on the object and property that is being animated.rest
viewAnimation diff Property Animation
1.The view animation system provides the capability to only animate View
objects
2.only exposes a few aspects of a View
object to animate, such as the scaling and rotation of a View but not the background color, for instance.
3.Another disadvantage of the view animation system is that it only modified where the View was drawn, and not the actual View itself
4.The property animation system is also more robust in the way it carries out animation.
5.The view animation system, however, takes less time to setup and requires less code to write
To have the ObjectAnimator
update properties correctly, you must do the following:
The object property that you are animating must have a setter function (in camel case) in the form ofset<propertyName>()
. Because the ObjectAnimator
automatically updates the property during animation, it must be able to access the property with this setter method. For example, if the property name is foo
, you need to have a setFoo()
method. If this setter method does not exist, you have three options:
Add the setter method to the class if you have the rights to do so.
Use a wrapper class that you have rights to change and have that wrapper receive the value with a valid setter method and forward it to the original object.
Use ValueAnimator
instead.
If you specify only one value for the values...
parameter in one of the ObjectAnimator
factory methods, it is assumed to be the ending value of the animation. Therefore, the object property that you are animating must have a getter function that is used to obtain the starting value of the animation. The getter function must be in the form of get<propertyName>()
. For example, if the property name is foo
, you need to have a getFoo()
method.
The getter (if needed) and setter methods of the property that you are animating must operate on the same type as the starting and ending values that you specify to ObjectAnimator
. For example, you must havetargetObject.setPropName(float)
and targetObject.getPropName(float)
if you construct the followingObjectAnimator
:
ObjectAnimator.ofFloat(targetObject, "propName", 1f)
Depending on what property or object you are animating, you might need to call the invalidate()
method on a View to force the screen to redraw itself with the updated animated values. You do this in theonAnimationUpdate()
callback. For example, animating the color property of a Drawable object only cause updates to the screen when that object redraws itself. All of the property setters on View, such as setAlpha()
and setTranslationX()
invalidate the View properly, so you do not need to invalidate the View when calling these methods with new values. For more information on listeners, see the section about Animation Listeners.