Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView Fails to Completely Render Content Until User Interaction

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?

like image 734
user1120134 Avatar asked Apr 30 '12 16:04

user1120134


1 Answers

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.

like image 75
Jorge Aguilar Avatar answered Nov 15 '22 18:11

Jorge Aguilar