我刚开始开发 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 时不会播放它。这是因为控制 GIF 动画是播放还是停止的 IsAnimationPlaying
属性的默认值为 false
。此属性的类型为 bool
,由 BindableProperty 对象支持,这意味着它可以作为数据绑定(bind)的目标并设置样式。
因此,当加载动画 GIF 时,它不会播放,直到 IsAnimationPlaying
属性设置为 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"/>
效果:
关于Xamarin GIF 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62935576/