Reputation: 141
I'm trying to animate a value from 0 to 100 then back to 0. So i figured ValueAnimator is best. I'm doing it like this
ValueAnimato animator = ValueAnimator.ofInt(0, 100);
animator.setInterpolator(INTERPOLATOR);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addUpdateListener(listener);
INTEPOLATOR is a LinearInterpolator and lister just logs the value. From the logs i see that it goes from 0 to a range near 100 than reverses. It reaches 100 a few times. My question is, shouldn't it always reach the value to 100. If not, is there any way to get that behaviour?
Edit I was trying to do something when target value is reached. I've used animation listener to do so now. But am still keeping the question open to understand the behaviour of animator better.
Upvotes: 2
Views: 834
Reputation: 23962
First thing - Animator
framework was designed to animate UI components. Therefore it does not make much sense to animate every possible value in range if user's eye won't catch it anyway. Boundaries of the repeating animation are not different from any value within the range - if you won't see the value of 100
on a next frame, what's the point for Animator
to go trough it?
So, what you should do? Do not attach any business logic to animation listener, especially since your animation is repeatable. Note, that some users might disable animations on their devices whatsoever (via Developer Settings).
Upvotes: 1