Animatedvectordrawablecompat Looping Animation Using Callback
I'm trying to implement an animation in my Android app using AnimatedVectorDrawableCompat, for compatibility for API >= 21. I want the animation to loop for the duration of the
Solution 1:
As far as I can see this is a subtle difference between the system & compat versions. Compat seems to call the callback before its animations have been flagged as having ended. So the call to start()
is ignored because it thinks it hasn't ended.
The solution is the usual hack: post a Runnable
to start it when the animations have finished.
newAnimatable2Compat.AnimationCallback() {
@NonNullprivatefinalHandlerfHandler=newHandler(Looper.getMainLooper());
@OverridepublicvoidonAnimationEnd(@NonNull Drawable drawable) {
Animatable2Compatavd= (Animatable2Compat) drawable;
fHandler.post(avd::start);
}
};
Post a Comment for "Animatedvectordrawablecompat Looping Animation Using Callback"