2017-01-30 2 views
1

나는 안드로이드 플랫폼을 가진 GIF의로드에 붙어 있기 때문에 오늘 올께.Xamarin Forms - WebView Html 소스 문제

그래서
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를 선언 :

을 나는

내가이 객체가 .. 그것이 그러나 안드로이드가 작동하지 않습니다, UWP와 iOS에서 작동하기 때문에 작동 알고
<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을 선언합니다.

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; 

또는 안드로이드에

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에게 줄 경우에만,이다 . 내 말은, HTML 텍스트로 100 %를 입력하면 실제 값을 줄 때와 달리 작동하지 않는다는 의미입니다. 어쩌면 WebView이 속성에 액세스 할 수 없습니다.

이제 화면의 크기는 어떻게됩니까?


안드로이드 :
App.ScreenSize = new Xamarin.Forms.Size((int)(Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density), (int)(Resources.DisplayMetrics.HeightPixels/Resources.DisplayMetrics.Density)); 

은 안드로이드 프로젝트의 MainActivity.cs

UWP에 포함 :
App.ScreenSize = new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height); 

이 UWP 프로젝트

을 당신의 MainPage.xaml.cs에 포함 PCL이 부분의 당신의 App.cs에서 5,

하는 public static Size ScreenSize;

즐기 선언!

관련 문제