首页 > 解决方案 > 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
                }
            };

标签: xamarinxamarin.android

解决方案


默认情况下,加载动画 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"/>

效果:

在此处输入图像描述


推荐阅读