I encounter a problem of display with a webview i'm using in one of my application.
When I call loadData, the webview first display the text and then load the images of the page (standard behaviour).
Sometimes, if those images modify the text position, the old text position is not cleared and both old text and new text+image is displayed
Here a screenshot of what it looks like when the problem occurs:
It's like the webview do not redraw correctly it's content. Of course a simple invalidate() does not work...
It do no occur often but lets say one time over 20.
Code used to display the data (called outside Activity life cycle methods):
// Include the html headers to the content received from WS
String webtext = String.format(ConfigApp.HTML_BODY, wsdata.getText());
mWebView.setWebChromeClient(...);
mWebView.setWebViewClient(...);
mWebView.setBackgroundColor(0);
mWebView.loadDataWithBaseURL(null, webtext, "text/html", "UTF-8", null);
Any idea how to fix this?
I've finally found a way to fix the problem.
Remove the WebView transparent background:
String webtext = String.format(ConfigApp.HTML_BODY, wsdata.getText());
mWebView.setWebChromeClient(...);
mWebView.setWebViewClient(...);
// mWebView.setBackgroundColor(0);
mWebView.loadDataWithBaseURL(null, webtext, "text/html", "UTF-8", null);
Because my WebView has a blank background it's ok for me. Maybe it can be annoying for somebody else.
For sure it's a WebView bug.
I have frequently had sporadic problems with WebViews not displaying properly after having loaded content with loadDataWithBaseUrl. Although the WebView's height was set to wrap_content, the WebView wouldn't always resize to wrap the content. Instead the webview had a height of zero. Sometimes it would display fine and other times it would not. Sometimes the problem would only happen in a portrait orientation and landscape would work fine. I tried removing my setBackgroundColor call but that it did not help. However, I was able to get the problem to go away today by changing the layout that the WebView was in from a LinearLayout to a RelativeLayout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With