【问题标题】:Gif Xamarin forms AndroidGif Xamarin 形成 Android
【发布时间】:2020-11-14 22:25:26
【问题描述】:

我知道 xamarin 表单目前支持播放 gif。 我已经尝试过链接https://github.com/jfversluis/AnimatedGifForms/ 但它似乎只适用于示例中类型的 gif,我尝试了另一个 gif,它无法在 android 上加载。 它在 IOS 上完美运行。 我可以做任何配置来以 xamarin 形式播放 gif 我正在使用 Xamarin.form 4.6 和最新的 Xamarin.Essential 1.5.3

【问题讨论】:

  • 在 WebView 中显示 gif 是否有效?
  • gif正常,可以在web上运行,sao webview很明显

标签: android xamarin xamarin.forms gif


【解决方案1】:

您可以使用Image 控件在 Xamarin.forms 中加载 gif。

<StackLayout>
    <!-- Place new controls here -->
    <Image Source="sample.gif" IsAnimationPlaying="True"
       HorizontalOptions="Center"
       VerticalOptions="CenterAndExpand" />
</StackLayout>

通过 IsAnimationPlaying 控制启动和停止。 最初我们打算使用 Start 和 Stop 方法,但所有这些 did 分别将 IsAnimationPlaying 设置为 true 或 false。这边走 也可以通过Binding来启动和停止!!

我上传了一个示例项目here,您可以查看。

参考:Gif Animation Support

更新

使用Xamarin.FFImageLoading.Svg.Forms加载:

xmlns:ffimageloading="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"

<StackLayout>

    <ffimageloading:SvgCachedImage HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Source="blue.gif" />

</StackLayout>

别忘了CachedImageRenderer.Init(true);MainActivity

protected override void OnCreate(Bundle savedInstanceState)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(savedInstanceState);

    //Forms.SetFlags("UseLegacyRenderers");

    CachedImageRenderer.Init(true);

    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
    LoadApplication(new App());
}

【讨论】:

  • 这很奇怪,因为我也可以在 android 上运行一些 gif,但有些不是这样,这可能取决于 gif 文件的大小或其他设置?
  • 你能分享给我们一个你不能在 Android 中运行的“gif”吗?
  • 这里是gif的链接,你可以看看
  • 是的,我测试了 gif,它在 iOS 中运行良好,而在 Android 中则不行。在 Android 中运行时出现 OutOfMemoryError。我发现的解决方法是您可以使用 Xamarin.FFImageLoading.Svg.Forms 加载该 gif。请查看我编辑的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多