I want my webview to autoscroll. Below is what I have tried, it does scroll the webview but it never stops i.e. it continues even after the webview has no content to display so it just displays the white screen. Please tell me how can it be fixed.
webview.setPictureListener(new PictureListener() {
public void onNewPicture(WebView view, Picture picture) {
webview.scrollBy(0, 1);
}
});
This code work for auto scroll as well as your scroll goes down then automatically come to top and then again start scroll. Check and if any query update me.
As best as I can tell, the only way to do this consistently with modern Android is with JavaScript:
The JavaScript APIs are aware of the size of the content.
This solution doesn't take into account changing viewport sizes,
window.innerHeight
rounding errors, ifdocument.body
isn't the scrolling element, etc.As for a Java-based solution, it seems the Java APIs give the size of the view, rather than the length of the page:
Maybe this changed when
enableSlowWholeDocumentDraw
was introduced.One Java API that is aware of the content length of the page is
canScrollVertically
but it returns false for a short time afteronPageFinished
is called. You could use some kind of delay to get around this. For example:I tested this on an Android API26 emulator and an Android TV API 22 emulator.
Try my code and hope it helps :) scroll down:
Scroll Up