2016-11-25 72 views
0

https://github.com/Emixam23/XamarinByEmixam23/tree/master/Detailed%20Part/Controls/GifProject無法通過Web視圖在Xamarin Forms中打開GIF

這是我所關注的項目。 當我運行代碼時,我沒有崩潰,但圖像也沒有顯示出來。在iOS上我得到一個「?」符號和Android上我找到經典的圖像符號,當你無法找到該文件。

接口:

namespace GifProject.Interface 
{ 
public interface IBaseUrl { string Get(); } 
} 

Rendererers: 的iOS:

[assembly: Dependency(typeof(BaseUrl_iOS))] 
namespace GifProject.iOS.DependencyService 
{ 
public class BaseUrl_iOS : IBaseUrl 
{ 
    public string Get() 
    { 
     return NSBundle.MainBundle.BundlePath; 
    } 
} 
} 

的Droid:

[assembly: Dependency(typeof(BaseUrl_Android))] 
namespace GifProject.Droid.DependencyService 
{ 
public class BaseUrl_Android : IBaseUrl 
{ 
    public string Get() 
    { 
     return "file:///android_asset/"; 
    } 
} 
} 

一直在做谷歌搜索關於Xamarin形式GIF格式的很多,但我一直沒能夠使它工作,所以任何提示,建議,可選解決方案非常感謝!

回答

1

主要問題是您的html源代碼字符串。 「寬度」和「高度」在不同的瀏覽器上有不同的效果。例如,我的測試顯示,如果您指定寬度爲百分比,則Android無法呈現圖像,但只能以像素爲單位。 那麼,是什麼在起作用肯定是個去除寬度和高度(以像素爲單位工作)

string imgSource = DependencyService.Get<IBaseUrl>().Get() + value; //Android and iOS don't seem to need Dependency just "value", so you might use Device.OnPlatform if you wish 

html.Html = String.Format(@"<html><body style='background: #000000;'><img src='{0}' /></body></html>", imgSource); 

夫婦的問題/建議考慮

  1. 如果使用相同的圖像,你可能想要把在PCL中
  2. 在Android中,您使用了Assets。爲什麼不是資源?

好運

+0

似乎不工作(當我嘗試在iOS ATLEAST)我得到像在頂部的白色小方離開 –

+0

和背景得到黑色 –

+0

如果我在iOS上運行它模擬器我得到一個「?」圖像在左上角 –