I'm calling to webview.scrollTo in onPageFinished function, but it doesn't do anything.
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
webview.scrollTo(0, scrollY);
}
Any idea why? How can I scroll a page automatically after it finished to load?
It appears to me that there's a race condition between the completion of
onPageFinished
,onProgressChanged
,WebView.scrollTo
, and the display (actually drawing to the screen) of the web page.After the page is displayed, the
WebView
'thinks' it has scrolled to yourscrollY
position.To test, you could verify that
WebView.getScrollY()
returns what you desire, but the display of the page is not in that position.To work around this issue, here is a non-deterministic approach to scroll to Y immediately after the page is presented:
The final parameter of 300 ms appears to allow the system to 'catchup' before the jumpToY is invoked. You might, depending upon platforms this runs on, play with that value.
Hope this helps
-Mike