I am currently having a problem with Android webview scrollTo function. I have it working properly (sometimes), but as I am clicking on the links in webview, it sometimes resets the screen back to 0,0 position.
Heres my code.
public void onPageFinished(WebView webview, String Url) {
final WebView newView = webview;
if (ScrollX > 0) { // <-- int variable containing users Scroll position
newView.postDelayed(new Runnable() {
public void run() {
if (view.getScrollX() > 0) {
// ScrollX and ScrollY sometimes get reset before scrollTo happens, Why?
newView.scrollTo(ScrollX, ScrollY);
pageloaded = true;
} else {
newView.scrollTo(ScrollX, ScrollY);
newView.post(this);
}
}
}, 10);
}
}
So here is whats going on. On my webviews onPageFinished, I am changing my webviews scroll position from the default 0,0 to whatever the user has their scroll position set to. I use the webviews postDelayed to delay things until the webview is completely loaded. Every 10ms my postDelayed checks to see if the webviews getScrollX() returns something > 0 (meaning webview has loaded). If it does, it goes into changing the webview scroll position section of the code and just finalizes that the webview has been loaded. If it doesn't, the code gets re ran after attempting to set the webviews scroll position. That way the next go around, my if statement can evaluate to true and avoid the rerun part of the code.
Now here is the problem, when I use view.getScrollX() > 0 to determine if webview has been loaded, it works fine. But sometimes, view.getScrollX() > 0 will evaluate to true. But when I use the webview scrollTo function, either my ScrollX and ScrollY variables are getting reset before scrollTo, or during scrollTo use and the webview just goes back to 0,0. Whats going on here?