Let's say I have a custom object, like a Point class (I am not using the one from Android), and I need to slowly change its coordinates from a start value to an end value when the user double taps the screen. I have already all setup, but I can't get to "animate" this change. Do you know how I can do it?
I have already tried something like this, but got no change: ObjectAnimator(point, "point.variable", final_value).start()
You may have set up the
ObjectAnimator
incorrectly.Let's assume your
Point
class has an instance variablexPosition
that is an Integer. In order to animate thexPosition
with theObjectAnimator
, you would do this:The
ObjectAnimator
will attempt to update the property automatically after each frame, but in order for it to be successful, your class must have a proper setter method for the property in the format ofsetYourProperty
. So in this particular example, your class must have a method calledsetXPosition
(note the camel case).If, for some reason, this is not working, then you fall back on a
ValueAnimator
. You set up theValueAnimator
a similar way.The difference here is that you must manually update your property. To do so, we add an
AnimatorUpdateListener
to the animation whoseonAnimationUpdate
method will be called after each frame in the animation.And don't forget to start the animation.
For more details regarding
ValueAnimator
andObjectAnimator
, see Google's API Guide on Property Animation: http://developer.android.com/guide/topics/graphics/prop-animation.html#value-animator