Xamarin GIF 动画

Ene*_*niz 2 xamarin.android xamarin

我刚刚开始开发 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
                }
            };
Run Code Online (Sandbox Code Playgroud)

Jun*_*ang 8

默认情况下,加载动画 GIF 时不会播放它。这是因为IsAnimationPlaying控制 GIF 动画是否正在播放或停止的属性的默认值为false。此属性(类型为bool)由 BindableProperty 对象支持,这意味着它可以是数据绑定和样式化的目标。

因此,当加载动画 GIF 时,只有将IsAnimationPlaying属性设置为 时才会播放它true

修改代码Image如下:

new Image { Source = "a.jpg", IsAnimationPlaying = true}
Run Code Online (Sandbox Code Playgroud)

例如,这是我的 gif 文件:

在此输入图像描述

XAML代码:

<Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="Start" />
<Image Source="timg.gif" IsAnimationPlaying="True"/>
Run Code Online (Sandbox Code Playgroud)

效果:

在此输入图像描述