Xamarin GIF 动画

标签 xamarin xamarin.android

我刚开始开发 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 文件:

enter image description here

Xaml 代码:

<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="Start" />
<Image Source="timg.gif" IsAnimationPlaying="True"/>

效果:

enter image description here

关于Xamarin GIF 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62935576/

相关文章:

android - 如何在 MonoDevelop 中编译 MonoDroid App 时修复 "OutOfMemoryError: java heap space"

android - Xamarin 强制我下载 Android SDK 和 NDK

xcode - MAC Cocoa 应用程序中的扩展列表

web-services - Xamarin:连接到本地托管的Web服务

mono - 如何在Mac上的Xamarin Studio中添加本地Nuget包源?

c# - String.Format() 不起作用,但 string.Format() 起作用

android - 在网格中添加 OxyPlot View

android - MonoDroid 为 EditText 设置最大值

xamarin.forms - 为什么我写的代码没有问题,但应用程序没有出现广告?

android - xamarin 谷歌地图不工作