xamarin - Xamarin Forms Lottie 图像未显示
问题描述
我有 Xamarin Forms 应用程序。我需要将图像作为 json 放在项目中。
这是 XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"
x:Class="xxx.Views.ScanReadyPage">
<StackLayout>
<forms:AnimationView
x:Name="lottie"
Animation="12240-cash-car.json"
Loop="False"
AutoPlay="True"
WidthRequest="200"
HeightRequest="200"
Margin="10,0,10,0"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
我已经安装了 Com.Airbnb.Xamarin.Forms.Lottie 版本 3.0.3 和 Xamarin.Forms 版本 4.3.0.991221
我已将从 lottiefiles.com: 12240-cash-car.json 下载的文件添加到 XamarinForms.Android 项目的 Assets 文件夹中,并将构建操作设置为 Android Asset。
Android 上没有显示任何内容。输出时没有信息,没有发生错误。我已将 Xamarin Forms 更改为 3.6.0 - 没有更改。我已经安装了 Lottie 的所有版本:从 2.6.3 到 3.0.3。- 没有显示图像。(版本 2.6.3 和更早版本有关于缺少密钥库的错误)。
我检查了版本后面的代码,但它也不起作用:
public MainPage()
{
element = new AnimationView()
{
Loop = true,
AutoPlay = true,
Animation = "12230-bounce-down-steps.json",
WidthRequest = 400,
HeightRequest = 400,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
IsVisible = true,
Speed = 1
};
}
AnimationView element = new AnimationView();
protected override void OnAppearing()
{
element.Animation = "12230-bounce-down-steps.json";
element.Play();
}
如何使它起作用?
解决方案
我在这里找到了解决方案:https ://iinteractive.com/notebook/2017/05/31/lottie-xamarin.html 。在所有 3 个项目中开始安装“Com.Airbnb.Xamarin.Forms.Lottie”。然后在 Android 项目中单独安装另一个库:“Com.Airbnb.Android.Lottie”。现在您可以转到 MainActivity.cs,输入“使用 Lottie.Forms.Droid”和“AnimationViewRenderer.Init(); 并且 json 图像正确显示。感谢Guilherme Nimer的好提示。
推荐阅读
- asp.net-core - System.TypeLoadException:'无法从程序集'WindowsBase,版本 = 4.0.0.0 加载类型'System.Windows.Size'
- python - 如何将 HTTP Basic Auth 用作单独的 FastAPI 服务?
- flutter - 在单个类中管理多个 setState() 方法?
- python - cli命令的顺序执行
- python - 如何创建一个数据框,它将在 Python 中给出多个数据框的摘要?
- c++ - 第二个对话框上的 C++ MFC 按钮什么也不做
- jenkins - 使用声明性管道将 Jenkins 变量注入 Maven
- powershell - 指定函数返回类型
- python - 通过 Process.Start() 启动的进程限制为 2 GB 内存
- swift - 表达式类型是模棱两可的类错误