I have created an AnimatedVectorDrawable, it works pretty well, now I am looking for a way to change the animation or hide the view after it finishes. I was hoping there was a listener but it doesn't look like there is. Can someone help?
EDIT
So I found a workaround, but not a very elegant way. What I did was create a thread and poll if the animation is running.
new Runnable() { public void run() { while(mLoop) { if(mAnimatedVectorDrawable.isRunning()) { Thread.sleep(mPollingInterval); } else { mLoop = false; // TODO what ever } } } };
If somebody finds a better solution, please share.
Not tried this yet but Android 6.0 has a registerAnimationCallback method from the Animatable2 interface for this
Edit: yep this works in Android 6.0 emulator:
mAnimatedVectorDrawable.registerAnimationCallback (new Animatable2.AnimationCallback(){ public void onAnimationEnd(Drawable drawable){ //Do something } }
Edit2: looks like they haven't added support for this in the AnimatedVectorDrawableCompat from support lib 23.2+ :(
Edit3: it looks like this got added in support lib 25.3.0
Thanks Carson!
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