【问题标题】:Android Xamarin: Detect Lottie Animation EndAndroid Xamarin:检测 Lottie 动画结束
【发布时间】:2018-09-12 13:41:25
【问题描述】:

我想在只包含一个 LottieAnimationView 的 DialogFragment 中扩展一个布局文件

<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"
  />

我希望 Fragment 出现,播放一次动画,并在动画结束后自动关闭。

我可以访问动画视图

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

但我找不到使用onAnimationEnd 方法或类似方法的方法。

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

但这并没有帮助我让它在我的情况下发挥作用。

【问题讨论】:

    标签: android animation xamarin nuget lottie


    【解决方案1】:

    您需要使用 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

    【讨论】:

      猜你喜欢
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多