Search code examples
androidanimationandroid-animationandroid-vectordrawable

Is there a way to listen for Animatable.isRunning changing?


I have been trying to make something happen after an AnimatedVectorDrawable is done animating and I was looking at the answer to this question regarding the AVDWrapper, but I have a gut feeling that there is a more elegant way.

Namely, setting a boolean change listener to check if anim.isRunning() has changed. I have been following this question and it's answers and have set up a boolean change listener (pretty much exactly the same way and setBoo to anim.isRunning()) but it's not working. Am I understanding something conceptually wrong here? The observer pattern should trigger at the end of the animation when anim.isRunning() changes from true to false. Or is it because an animation is time sensitive/continuous and needs to be continuously polled, therefore this won't work? How about if the listener implements Runnable?

Thank you.


Solution

  • Use a custom Animatable2.AnimationCallback and call anim.registerAnimationCallback().