Xamarin GIF动画

eeq64g8w  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(185)

我刚开始开发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
                }
            };
mcdcgff0

mcdcgff01#

By default, when an animated GIF is loaded it will not be played. This is because the IsAnimationPlaying property, that controls whether an animated GIF is playing or stopped, has a default value of false . This property, of type bool , is backed by a BindableProperty object, which means that it can be the target of a data binding, and styled.

Therefore, when an animated GIF is loaded it will not be played until the IsAnimationPlaying property is set to true .

Modify code of Image as bellow :

new Image { Source = "a.jpg", IsAnimationPlaying = true}

For example , this is my gif file :

Xaml code :

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

The effect :

lstz6jyr

lstz6jyr2#

请使用nuget包-Xamarin.FFImageLoading。它处理GIF文件的速度很快。
例如XAML -
<ffimageloading:SvgCachedImage Grid.Row="3" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Source="celebrate.gif" />

相关问题