Webview loaddata scroll settings are not updated until click

I am updating html in webView with loadData () followed by reload (). I get new data to display, but page scrolling is not updated. I want to keep the page view below. I can wait a long time, and it still has not been updated. As soon as I click on webView, adjust the scrollbars and I can drag them to the bottom of the page and see the new text.

Things I tried: - a few settings and calls in onPageFinished (). Nothing worked because getContentHeight () has not changed yet. I also tried scrolling the page (100 + getContentHeight) and this would not work. - pageDown (true)

  • call requestLayout () after reload ()

  • browser.requestFocusFromTouch () - still no good thinking that I can simulate my click.

  • adding multiple br tags This worked a little, but the number br should equal the number of lines of new text. Since the number of newlines is not something that can be accurately determined based on orientation and screen variables, this is not a good solution. Any ideas? TIA

+2
source share
1 answer

If you want the webview to scroll to the end after the download is complete, I find that I need to use pageDown (true) in onNewPicture. (I believe the event was fired when the view ended with drawing.)

So the code looks something like

   webView.setPictureListener( new WebView.PictureListener() {

        public void onNewPicture(WebView view, Picture picture) {
            webView.pageDown(true);
        }
    }

pageDown ; - webView, , ! ( WebView javascript.)

+4

Source: https://habr.com/ru/post/1768156/


All Articles