2014-10-11 100 views
0

當我打開帶有webView第一次圖像(.bg css類)的片段時,無法加載,但每隔一個打開加載正確。爲什麼?Android WebView第一次沒有從資產加載圖像

代碼的html:在片段

<style> 
... 
.bg 
    { 
     background: url('image.png') center center no-repeat; 
     background-size: cover; 
     width: 100%; 
     height: 100%; 
     position: fixed; 
     top: 0; 
    } 
... 
</style> 
... 
<body> 
    <div class='bg'></div> 
    <div class='content'> 
    ... 
    </div> 
</body> 

代碼顯示HTML:

_handler.Post(() => {       
        var settings = webView.Settings; 
        webView.Settings.JavaScriptEnabled = true; 
        webView.Settings.DomStorageEnabled = true; 
        settings.AllowFileAccess = true; 
        settings.AllowFileAccessFromFileURLs = true; 
        settings.AllowContentAccess = true; 
        settings.AllowUniversalAccessFromFileURLs = true; 
        settings.DefaultTextEncodingName = "utf-8"; 
        webView.Visibility = ViewStates.Visible; 
        webView.LoadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null); 
       }); 

UPD: 我認爲它不是一個併發的問題,因爲如果我把所有的代碼進入UI線程,並刪除所有的WebView可見性變化這個錯誤繼續重現。

+0

這看起來像是一個併發問題。您可能會在第一次加載之前顯示Web視圖,並且您的所有下一個加載都已從第一次加載中加載加載的數據。 如果是這樣的話,我會建議子類別'WebViewClient'和重載'OnPageFinished'以顯示加載後的web視圖 – 2014-10-12 08:37:02

+1

另一件事,如果您使用'_handler.Post'推遲下一次UI更新的負載,這不應該是一個問題,但我會嘗試沒有'Post'只是爲了安全起見 – 2014-10-12 08:39:10

回答

0

我遇到了同樣的問題。不知道它是否與你的情況相同。我花了3天多時間,發現另一個WebView對象調用pauseTimers()來保存某些CPU性能的原因實際上是「暫停所有WebView的佈局,解析和JavaScript定時器」。

相關問題