【发布时间】:2017-06-23 12:28:59
【问题描述】:
我正在尝试使用 Xamarin.Forms(便携式)项目播放 GIF 图像。我已使用以下代码实现但无法播放 GIF,我没有看到静态图像。
这段代码没有错误或崩溃,但我看不到 GIF 图片。
代码有问题吗?
界面:
public interface IGif
{
string Get();
}
iOS 实现:
[assembly: Dependency(typeof(GifView_iOS))]
namespace Project.iOS
{
public class GifView_iOS : IGif
{
public string Get()
{
return NSBundle.MainBundle.BundlePath;
}
}
}
Android 实现:
[assembly: Dependency(typeof(GifView_Droid))]
namespace Project.Droid
{
public class GifView_Droid : IGif
{
public string Get()
{
return "file:///android_asset/";
}
}
}
GIF 图片类:
public class Gif: WebView
{
public string GifSource
{
set
{
string imgSource = DependencyService.Get<IGif>.Get() + value;
var html = new HtmlWebViewSource();
html.Html = String.Format
(@"<html><body style='background: #000000;'><img src='{0}' /></body></html>",
imgSource);
SetValue(SourceProperty, html);
}
}
}
最后,我已添加到 StackLayout。
Gif gifimage = new Gif();
gifimage.GifSource = "loading.gif";
StackGif.Children.Add(gifimage);
我没有在 iPhone 上测试过这段代码,也许它在 iPhone 上可以工作。
提前谢谢你。
【问题讨论】:
-
发生了什么?它会崩溃吗?它不显示任何东西吗?您收到错误消息吗?堆栈跟踪?请阅读here,了解如何在 StackOverflow 上提出一个好问题。
-
其实没有问题或者崩溃,但是我看不到
GIF的图片。
标签: android xamarin xamarin.ios xamarin.forms animated-gif