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



我正在使用Xamarin.Android进行这项工作,并且我已经将testanim.json文件放在资产文件夹中。当我运行该应用程序时,它总是抛出错误 找不到文件异常 下面是我的 Lottie 动画的 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);

我终于找到了解决方案:

问题:资产文件夹中的 yourfile.json 动画文件已将"生成操作"设置为"无"。

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

注意:如果您已将文件添加到资源/原始文件夹中,请转到 json 文件属性并将构建操作设置为 AndroidResrouce,我使用了下面给出的代码来引用资源/原始中的动画

animationView.SetAnimation(Resource.Raw.animationFile);

请记住:不要在动画文件名中使用"-",而要使用"_"。

相关内容

最新更新