webview loaddata scroll setting not updating till clicked

折月煮酒 提交于 2019-12-22 09:49:20

问题


I update the html in a webView using loadData() followed by a reload(). I get the new data to display but the scroll of the page has not updated. I want to keep the view of the page at the bottom. I can wait a long time and it still doesn't update. Once I click the webView the scroll bars adjust and I can drag to the bottom of the page and see the new text.

Things I have tried: - multiple settings and calls in onPageFinished(). None worked because the getContentHeight() hasn't changed yet. I have also tried to scrollTo(100 + getContentHeight) and that doesn't work. - pageDown(true)

  • calling requestLayout() after reload()

  • browser.requestFocusFromTouch() - still no good, thinking i could simulate my click.

  • adding a few br tags. This worked a bit, but the number of br's has to equal the number of lines of new text. Since the number of new lines is not something that can be exactly determined based on orientation and screen variables it's not a good fix. Any ideas? TIA


回答1:


If you want the webview to be scrolled to the bottom after it's finished loading, I found I had to use pageDown(true) in onNewPicture. (I believe that's the event fired when a view is finished drawing.)

So the code looks something like

   webView.setPictureListener( new WebView.PictureListener() {

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

Using pageDown has the unfortunate problem of visibly scrolling the page; I'm having problems finding any other way to jump to the bottom of the webView, found this question while looking for a solution! (I haven't tried reaching inside the WebView and using javascript yet, though.)



来源:https://stackoverflow.com/questions/3953791/webview-loaddata-scroll-setting-not-updating-till-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!