未找到Lottie Animations JSON动画文件Xamarin Android异常

时间:2018-09-28 06:17:50

标签: c# android xamarin xamarin.android

我正在使用Xamarin.Android进行此项工作,并将testanim.json文件放置在Assets文件夹中。当我运行该应用程序时,它总是会引发错误“文件未找到”异常,这是我的Lottie Animation的XML代码

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

我的C#代码如下:

LottieAnimationView animationView = FindViewById<LottieAnimationView>(Resource.Id.animation_view);
animationView.SetAnimation("testanim.json");
animationView.Loop(true);

1 个答案:

答案 0 :(得分:2)

我终于找到了解决方法:

问题: Assets文件夹中的yourfile.json动画文件的Build Action设置为None。

解决方案: 右键单击yourfile.json动画文件,然后转到属性,然后将“构建操作”设置为AndroidAssets。现在,在项目中构建并查看动画。

注意::如果您已将文件添加到Resources / raw文件夹中,请转到json文件属性并将Build Action设置为AndroidResrouce,我已使用下面给出的代码引用Resource / raw中的动画< / p>

animationView.SetAnimation(Resource.Raw.animationFile);

记住::请勿在动画文件名中使用“-”,而应使用“ _”。

相关问题