I'm so confused as to how ValueAnimator works in Android. Here's a code snippet (pseudo):
Log("animating: ", start, end);
ValueAnimator animator = ValueAnimator.ofFloat(start, end);
animator.setUpdateListener(() -> {
Log("update", animation.getAnimatedFraction());
});
animator.start();
I see the following in my logs:
animating: 0.0 to 1.0
update: 0.0
update: 0.05
..
update: 1.0
animating: 1.0 to 0.0
update: 0.0 (wtf)
update: 0.05
..
update: 1.0
animating: 0.5 to 1.0
update: 1.0 (wtf)
update: 1.0
Can someone explain to me why my update function is getting these strange values?
Why don't you use getAnimatedValue
? It's exactly that value that calculated while property changing, it's not a fraction:
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float value = (Float) animation.getAnimatedValue();
Log("update", String.valueOf(value));
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With