开发者

Android WebView.loadDataWithBaseURL first page load is a mess. How to fix it?

I use WebView.loadDataWithBaseURL for loading my help page from internal resources of my application.

I have help.html and a few images located in the assets directory. The page loads and shows with images, but the text around image is a mess. It did not show on the right side of the image开发者_如何学Go, instead the image overlaps the text.

This happens only on first loading of the page. If I close the WebView and open it again, then everything is fine. It seems that at first loading WebView spends some time for loading images and does not reformat page after that. On the second attempt images are cached and displayed together with text and properly formatted.

What is the solution for this problem?

Did anyone face this problem too?

Here is my code:

    app.setContentView(R.layout.help);
    final WebView web = (WebView) app.findViewById(R.id.helpWebView);
    web.setBackgroundColor(0);
    web.loadDataWithBaseURL("file:///android_asset/", helpHtml, "text/html", "utf-8", null);        

Web page is inside the helpHtml string with the code:

<html><head></head><body><img src="html/flddesc.png" align="left"/>this should be my long long text...</body></html>

P.S: html/flddesc.png is a PNG8 image 180x200 ~20kb of size


Try this function:

webview.loadUrl("file:///android_asset/your_html.html");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜