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可见性变化这个错误继续重现。
这看起来像是一个并发问题。您可能会在第一次加载之前显示Web视图,并且您的所有下一个加载都已从第一次加载中加载加载的数据。 如果是这样的话,我会建议子类别'WebViewClient'和重载'OnPageFinished'以显示加载后的web视图 – 2014-10-12 08:37:02
另一件事,如果您使用'_handler.Post'推迟下一次UI更新的负载,这不应该是一个问题,但我会尝试没有'Post'只是为了安全起见 – 2014-10-12 08:39:10