xamarin - Xamarin GIF 动画
问题描述
我刚开始开发 Xamarin 但我遇到了一个问题 我有一个登录屏幕,我想在那里播放 gif 但不幸的是没有图像出现
适用于 png 和 jpeg 文件
我的代码如下;
Content = new StackLayout
{
Padding = new Thickness(10, 40, 10, 10),
Children = {
new Label { Text = "Versiyon:"+DependencyService.Get<INativeCall>().getApplicationVersion(), FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), TextColor = Color.White, HorizontalTextAlignment=TextAlignment.Center },
new Image { Source = "a.gif" },
username,
password,
btnLogin,
indicator,
infoServer,
infoUpdate
}
};
解决方案
默认情况下,加载动画 GIF 时不会播放。这是因为IsAnimationPlaying
控制动画 GIF 是播放还是停止的属性的默认值为false
. 此类型的属性bool
由 BindableProperty 对象支持,这意味着它可以是数据绑定的目标,并且可以设置样式。
因此IsAnimationPlaying
,当加载动画 GIF 时,在属性设置为之前不会播放它true
。
修改代码Image
如下:
new Image { Source = "a.jpg", IsAnimationPlaying = true}
例如,这是我的 gif 文件:
Xaml 代码:
<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="Start" />
<Image Source="timg.gif" IsAnimationPlaying="True"/>
效果:
推荐阅读
- arrays - 如何快速从 Firestore 中读取不同的数据类型
- javascript - js中的排序算法有两个条件
- python - 数据帧的真值只有在通过 Tkinter 运行时才模棱两可
- python - 事件网格使用 blob 存储输入和输出 Python 触发 Azure Functions
- swagger - Docebo web api 是否支持 Swagger?
- javascript - img-wrapper 不显示 png
- javascript - 未处理的承诺拒绝 | 重启命令
- asp.net-core - Azure DevOps:“rzc generate exited with code 2”
- java - 如何解决本地计算机上的 Tomcat 问题
- raku - 从 Raku HTTP 客户端请求中提取 JSON