Issue
I have a webview loading a big texts after the user has clicked an object. I like the text to be shown from the top. But if the user scrolled down in the previous text the next is already scrolled and not shown from the top.
I am using webView.scrollTo(0,0); in my onPageFinished event of the webview.
This works fine in my emulator, but on my phone the text is scrolled in the middle.
when adding a pause with Thread.sleep it also works on my phone. What am I doing wrong here ?
My Code:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
// Pause is needed for my physical phone S7. In Emulator there I have no problem.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
webView.scrollTo(0,0);
super.onPageFinished(view, url);
}
});
Solution
Try with this block of code -
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
// Pause is needed for my physical phone S7. In Emulator there I have no problem.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
view.scrollTo(0,0);
super.onPageFinished(view, url);
}
});
Actually, you're so close to the solution. Just the point is you need to set scrollTo in the returned view of onPageFinished method.
Answered By - Al-Amin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.