[英]Lottie Animations JSON Animation file not found exception Xamarin Android
I am using Xamarin.Android for this work and I have placed my testanim.json file in assets folder. 我正在使用Xamarin.Android进行此项工作,并将testanim.json文件放置在资产文件夹中。 When I run the app it always throws error File not found exception below is my XML code for Lottie Animation
当我运行该应用程序时,它始终会引发错误“文件未找到”异常,这是我的Lottie Animation的XML代码
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
My C# code is as follows: 我的C#代码如下:
LottieAnimationView animationView = FindViewById<LottieAnimationView>(Resource.Id.animation_view);
animationView.SetAnimation("testanim.json");
animationView.Loop(true);
I have found the solution finally: 我终于找到了解决方案:
Problem: yourfile.json animation file in assets folder had Build Action set to None. 问题: assets文件夹中的yourfile.json动画文件的Build Action设置为None。
Solution: Right click on yourfile.json animation file and go to properties and set the Build Action to AndroidAssets. 解决方案:右键单击yourfile.json动画文件,然后转到属性,并将“构建操作”设置为AndroidAssets。 Now build and see your animation in project.
现在构建并在项目中查看动画。
Note: If you have added file into Resources/raw folder then go to json file properties and set the Build Action to AndroidResrouce and I have used below given code to reference animation from Resource/raw 注意:如果您已将文件添加到Resources / raw文件夹中,则转到json文件属性,并将Build Action设置为AndroidResrouce,并且我在下面使用了给定的代码来引用Resource / raw中的动画
animationView.SetAnimation(Resource.Raw.animationFile);
Remember: Do not use the '-' in your animation file name instead use '_'. 切记:不要在动画文件名中使用“-”,而应使用“ _”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.