I try to scroll down the page I have in my WebView. Therefore I found the function .pageDown(true). The problem is that this function does not really work for me. Mostly it does not do anything.
Codesnippet:
wvChat.loadData(chat_, "text/html; charset=utf-8", "UTF-8");
wvChat.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
wvChat.pageDown(true);
}
});
Is there another method or is it wrong to use it in onPageFinished?
get the html content height and use scrollTo(x,y)
wvChat.loadData(chat_, "text/html; charset=utf-8", "UTF-8");
wvChat.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
//use the param "view", and call getContentHeight in scrollTo
view.scrollTo(0, view.getContentHeight());
}
});
I have a solution to scroll down large files (much lines) using the scrollTo function. I set a much higher value than the content height can be.
mWebView.setWebViewClient(new WebViewClient()
{
@Override
public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
Handler lHandler = new Handler();
lHandler.postDelayed(new Runnable()
{
@Override
public void run()
{
mWebView.scrollTo(0, 1000000000);
}
}, 200);
}
});
The problem is now, that it does not work for small files (less lines), because the onPageFinished method is called before the WebView has been rendered, so I have to use a delay handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With