我正在使用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);
答案 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);
记住::请勿在动画文件名中使用“-”,而应使用“ _”。