2016-07-05 20 views
0

我一直在問自己,並且在網上找不到有趣的東西。我從來沒有與WebView合作過,但我發現了一些關於它的事情,似乎有可能創建自己的WebPageXamarin表單 - 將GIF存儲到WebView中

然後是有可能創造一個WebPage(在WebView)和投入到這個WebView(或WebPage)一個GIF?

我也明白,我想,我可以WebView鏈接到GIF的鏈接在網絡上,但對於數據交換,我想它存儲在手機上,而不是加載每次它。

那麼,有可能嗎?

提前致謝!

回答

1

從Xamarins docs

// define a interface 
public interface IBaseUrl { string Get(); } 

// load html 
var html = new HtmlWebViewSource(); 
html.BaseUrl = DependencyService.Get<IBaseUrl>().Get(); 

htmlSource.Html = @"<html> 
    <head> 
    <link rel=""stylesheet"" href=""default.css""> 
    </head> 
    <body> 
    <h1>Xamarin.Forms</h1> 
    <p>The CSS and image are loaded from local files!</p> 
    <img src='Images/XamarinLogo.png'/> 
    </body> 
    </html>"; 

webView.Source = html; 

然後,您將需要實現IBaseUrl爲你想支持每個平臺。對於iOS,它看起來像這樣:

[assembly: ExportRenderer (typeof (BaseUrlWebView), typeof (BaseUrlWebViewRenderer))] 
namespace WorkingWithWebview.iOS { 
    public class BaseUrlWebViewRenderer : WebViewRenderer { 
     public override void LoadHtmlString (string s, NSUrl baseUrl) { 
      baseUrl = new NSUrl (NSBundle.MainBundle.BundlePath, true); 
      base.LoadHtmlString (s, baseUrl); 
     } 
    } 
} 
+0

感謝您的回答,但它可以像您對GIF文件顯示的那樣簡單地工作?不要忘記,這個GIF是一個動畫而不是一個簡單的圖像 – Emixam23

+0

我不知道它爲什麼不會。但是你必須測試它才能確定。 – Jason

+0

我稍後再測試,謝謝:) – Emixam23