I’m working on Lottie animation in android but Lottie animation callback function is not called.
XML file:
<com.airbnb.lottie.LottieAnimationView
android:layout_width="@dimen/margin_15"
android:layout_height="@dimen/margin_15"
android:id="@+id/lav_LikeAnim"
app:lottie_autoPlay="true"
app:lottie_fileName="handshake_lottie.json"
app:lottie_loop="false"
android:visibility="gone"
android:scaleX="2"
android:scaleY="2"
android:layout_gravity="center"
/>
Code: After response of liked:
try {
likeLottieAnim.playAnimation();
likeLottieAnim.setVisibility(View.VISIBLE);
iv_like.setVisibility(View.GONE);
tv_likes_count.setVisibility(View.GONE);
} catch (Exception exception) {
exception.printStackTrace();
Logger.i(TAG,"Lottie_animation_exception :"+exception);
}
Code: Callback : It’s not called after lottieAnimation Play(likeLottieAnim.playAnimation()), I debug it but no succeed.
likeLottieAnim.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
iv_like.setVisibility(View.GONE);
tv_likes_count.setVisibility(View.GONE);
}
@Override
public void onAnimationEnd(Animator animation) {
try {
iv_like.setVisibility(View.VISIBLE);
tv_likes_count.setVisibility(View.VISIBLE);
likeLottieAnim.setVisibility(View.GONE);
} catch (Exception exception) {
exception.printStackTrace();
Logger.i(TAG,"Lottie_animation_exception :"+exception);
}
iv_like.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_liked));
}
@Override
public void onAnimationCancel(Animator animation) {
Logger.i(TAG,"onAnimationCancel :");
}
@Override
public void onAnimationRepeat(Animator animation) {
Logger.i(TAG,"onAnimationRepeat :");
}
});
where I made the mistake?
2
Answers
Sorry guys, I caught a mistake in XML file, Lottie define it under another Linearlayout. I changed the position and now it's fixed.
I ran into this problem on the emulator. After searching for the reason, I see that an option called ‘Remove Animations’ is enabled in the accessibility of the emulator.
I have seen that if this option is enabled, Lottie Animation does not work and Lottie callback Listener is not called in the Android
Try disabling the ‘Remove Animations’ option in the accessibility of the emulator or your device.