What's the difference between ObjectAnimator and ViewPropertyAnimator changing property value?
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(myObject, "X", 0.0f, 100.0f);
I tried myObject.getX() while above objectAnimator is ongoing, and I got a on-the-way value between 0.0f to 100.0.
myObject.setX(0.0f);
myObject.animate().x(100.0f);
However, I got precise 100.0 when I myObject.getX()'d while above ViewPropertyAnimator is ongoing.
I can't figure out what makes this difference.
Thanks in advance.
When you request to animate the
xfield using aViewPropertyAnimator, it doesn't actually animate thexfield - it animates thetranslateXfield. This is why you can't see thexfield change.From the Android source code in ViewPropertyAnimator.java:
ObjectAnimatoron the other hand uses reflection to animate properties - rather than a preset list of supported actions. And so when you tell it to animate the "X" field, it calls "setX" directly.