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
ObjectAnimatorincorrectly.Let's assume your
Pointclass has an instance variablexPositionthat is an Integer. In order to animate thexPositionwith theObjectAnimator, you would do this:The
ObjectAnimatorwill 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 theValueAnimatora similar way.The difference here is that you must manually update your property. To do so, we add an
AnimatorUpdateListenerto the animation whoseonAnimationUpdatemethod will be called after each frame in the animation.And don't forget to start the animation.
For more details regarding
ValueAnimatorandObjectAnimator, see Google's API Guide on Property Animation: http://developer.android.com/guide/topics/graphics/prop-animation.html#value-animator