Android WebView Fails to Completely Render Content

2019-04-04 02:45发布

问题:

I have a custom class extending WebView that displays HTML content. When the user clicks a link in the HTML document, I calculate an X value to scroll to, and then use scrollTo(x,y) to show that location via a runnable (see below)

 post( new Runnable() {

            @Override
            public void run() {

                scrollTo( x, 0 );
                MyWebView.this.invalidate();
                MyWebView.this.buildDrawingCache();
                MyWebView.this.refreshDrawableState();
                MyWebView.this.postInvalidate();
            }
        } );

After scrolling, there is a chance that the webview will fail to render the entire document. Rectangular chunks of white space are shown where text should be, with seemingly random placement each time. Here is a screenshot: http://i.imgur.com/g192Y.jpg

When I touch the webview to scroll, it will immediately render the missing portions.

So far this behavior is constrained to the Samsung Galaxy 10.1" tablet.

Does anyone know a workaround / how to force webkit to re-render the page?

回答1:

Well i am having the exact same problem here with that tablet, the only difference is that i am using iscroll to do all the scrolling. The solution i am using for this problem is to "scroll" via JavaScript a hidden DIV and that fixed the problem. i hope this can help anyone with the same problem. If you use iscroll they have a method to "scroll" to a fixed position, maybe that can help you also, if not is not that hard to detect the touchmove or mousemove events. The point here is that you just need to fake a scroll anywhere on the html even if is not visible.