0

I want to inflate a Layout-File in my DialogFragment which only holds one LottieAnimationView

<com.airbnb.lottie.LottieAnimationView
  android:id="@+id/animViewTest1"
  android:layout_height="100dp"
  android:layout_width="100dp"
  app:lottie_fileName="json_Saved.json"
  app:lottie_loop="false"
  app:lottie_autoPlay="false"
  />

I want the Fragment to show up, play the animation once, and automatically close, after the animation is finished.

I can access the AnimView

animView = view.FindViewById<LottieAnimationView>(Resource.Id.animViewTest1);
animView.PlayAnimation();

but i can't find a way to get to the onAnimationEnd Method or something similar.

I found this similar question: How to know when lottie animation is completed?

But it does not helped me to make it work in my case.

Aiko West
  • 791
  • 1
  • 10
  • 30

1 Answers1

2

You need to use IAnimatorListener listener, just implement it by your class:

YourClass : IAnimatorListener

with all needed methods, one of them is what you're after:

public void OnAnimationEnd(Animator animation)
{
// your logic on animation end
}

and then assign your IAnimatorListener implementation as animator listener of your lottie view:

this.animationView.AddAnimatorListener(implementationOfIAnimatorListener);

You can find a full example on Lottie Xamarin github: https://github.com/martijn00/LottieXamarin/blob/develop/Samples/Native/Example.Droid/AnimationFragment.cs

Michał Żołnieruk
  • 2,095
  • 12
  • 20