2017-01-30 11 views
1

アンドロイドプラットフォームでGIFの読み込みが滞っているので、今日は来ています。私は、このオブジェクトを持つXamarinフォーム - WebView HTMLソースの問題

...それはそれは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); } 
    } 
} 

だから私はちょうど私のXAML側でこのGifを宣言:

<AbsoluteLayout AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 1" AbsoluteLayout.LayoutFlags="All"> 
      <control:Gif 
       AbsoluteLayout.LayoutBounds="0.5, 0, 1, 0.9" 
       AbsoluteLayout.LayoutFlags="All" 
       BackgroundColor="Red" 
       GifSource="Gifs/LoginBackground.gif" /> 
      <BoxView 
       AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 1" 
       AbsoluteLayout.LayoutFlags="All" 
       BackgroundColor="Transparent" /> 
</AbsoluteLayout> 

PS:私はBoxViewを宣言して、ユーザーのジェスチャーでWebビューを移動する可能性を逃しています。

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"; 

this.Source = "https://media.giphy.com/media/UGifMFmx0gERG/giphy.gif";作品は、しかし、最初の解決策はないの:

は今のものは、それがコードの両方で、完全にUWP上で動作、です仕事、これは問題です。私自身のhtmlを作成することで、GIFをリンクとは違う私の見解にすることができます...さらに多くの点で、htmlのstyle='width:100%;height:100%;'を削除すれば、それはうまく動作しますが、もう一度、良いサイズではありません。

ご存知ですか?少し早いですがお礼を !

答えて

0

:)

私は解決策を見つけ、それは奇妙だが、私はこのコードを持っている:

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); 

奇妙な最初にすることは、ことを100%値の作品ですが、私はWebViewにそれを与える場合にのみ、 。私が意味することは、100%をHTMLテキストとして入力すると、実際の価値を出すときとは違って、うまくいきません。 WebViewでプロパティにアクセスできない可能性があります。

どうすれば画面のサイズを取得できますか?


アンドロイド:

App.ScreenSize = new Xamarin.Forms.Size((int)(Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density), (int)(Resources.DisplayMetrics.HeightPixels/Resources.DisplayMetrics.Density)); 

あなたのAndroidプロジェクト

UWPのごMainActivity.csでそれを含める:

App.ScreenSize = new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height); 

は、あなたのUWPプロジェクトのごMainPage.xaml.cs

でそれを含めますPCL一部のご App.cs

public static Size ScreenSize;

お楽しみを宣言!

関連する問題