0

我想在我的 DialogFragment 中膨胀一个布局文件,它只包含一个 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"
  />

我希望片段显示出来,播放一次动画,并在动画完成后自动关闭。

我可以访问 AnimView

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

但我找不到方法来获得onAnimationEnd方法或类似的东西。

我发现了这个类似的问题:How to know when lottie animation is done?

但这并没有帮助我使它适用于我的情况。

4

1 回答 1

2

您需要使用 IAnimatorListener 侦听器,只需通过您的类实现它:

YourClass : IAnimatorListener

使用所有需要的方法,其中之一就是您所追求的:

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

然后将您的 IAnimatorListener 实现分配为您的 lottie 视图的动画侦听器:

this.animationView.AddAnimatorListener(implementationOfIAnimatorListener);

您可以在 Lottie Xamarin github 上找到完整示例:https ://github.com/martijn00/LottieXamarin/blob/develop/Samples/Native/Example.Droid/AnimationFragment.cs

于 2018-04-03T11:36:12.970 回答