Android Xamarin表单-WebView Html源代码问题

Android Xamarin表单-WebView Html源代码问题,android,webview,xamarin.forms,gif,Android,Webview,Xamarin.forms,Gif,我今天来是因为我被安卓平台的GIF文件卡住了。我知道它是有效的,因为它适用于UWP和iOS,但是android不起作用 我有一个目标: public class Gif : WebView { public string GifSource { set { var html = new HtmlWebViewSource(); html.Html = String.Format(@"<html&

我今天来是因为我被安卓平台的GIF文件卡住了。我知道它是有效的,因为它适用于UWP和iOS,但是android不起作用

我有一个目标:

public class Gif : WebView
{
    public string GifSource
    {
        set
        {
            var html = new HtmlWebViewSource();
            html.Html = String.Format(@"<html><body style='background: #FF0000;'><img src='{0}' style='width:100%;height:100%;'/></body></html>", "https://media.giphy.com/media/UGifMFmx0gERG/giphy.gif");
            Debug.WriteLine("Html.Source = '{0}'", html.Html);
            this.Margin = -10;
            this.Source = html;
        }
        get { return (string)GetValue(SourceProperty); }
    }
}
注:我声明了一个
BoxView
,以避免通过用户手势移动webview的可能性

现在的问题是,它在UWP上完美地工作,有两种代码:

html.Html = String.Format(@"<html><body style='background: #FF0000;'><img src='{0}' style='width:100%;height:100%;'/></body></html>", "https://media.giphy.com/media/UGifMFmx0gERG/giphy.gif");
this.Source = html;
在Android上,
this.Source=”https://media.giphy.com/media/UGifMFmx0gERG/giphy.gif";起作用,但是第一个解决方案不起作用,这是一个问题。通过创建我自己的html,它允许我使gif填充我的视图,而不像链接。。。更重要的是,如果我删除
style='width:100%;身高:100%;'的html,它的工作,但一次又一次,不好的大小

有什么想法吗?提前感谢

:)

我找到了一个解决方案,这很奇怪,但我有以下代码:

html.Html = String.Format(@"<html><body style='background: #000000;'><img src='{0}' style='width:{1};height:{2};'/></body></html>",
 DependencyService.Get<IBaseUrl>().Get() + value, App.ScreenSize.Width, (App.ScreenSize.Height / 100) * 90);
将其包含在Android项目的
MainActivity.cs

UWP: 将其包含在UWP项目的
MainPage.xaml.cs


在PCL部分的
App.cs
中,声明一个
公共静态大小屏幕大小

享受吧

:)

我找到了一个解决方案,这很奇怪,但我有以下代码:

html.Html = String.Format(@"<html><body style='background: #000000;'><img src='{0}' style='width:{1};height:{2};'/></body></html>",
 DependencyService.Get<IBaseUrl>().Get() + value, App.ScreenSize.Width, (App.ScreenSize.Height / 100) * 90);
将其包含在Android项目的
MainActivity.cs

UWP: 将其包含在UWP项目的
MainPage.xaml.cs


在PCL部分的
App.cs
中,声明一个
公共静态大小屏幕大小

享受吧

html.Html = String.Format(@"<html><body style='background: #000000;'><img src='{0}' style='width:{1};height:{2};'/></body></html>",
 DependencyService.Get<IBaseUrl>().Get() + value, App.ScreenSize.Width, (App.ScreenSize.Height / 100) * 90);
App.ScreenSize = new Xamarin.Forms.Size((int)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density), (int)(Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density));
App.ScreenSize = new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height);