Webview height not changing after resize font size

▼魔方 西西 提交于 2019-12-31 02:03:31

问题


In my application I use a ScrollView. This ScrollView contain many Webview. I change the webview font size:

webView.getSettings().setTextSize(WebSettings.TextSize.LARGER);

after I change again the font size:

webView.getSettings().setTextSize(WebSettings.TextSize.SMALLER);

The font size is changing, but the webview layout height is not changing. The text is smaller and there are a big space. There are any method to this problem?


回答1:


you might have to reload your webview with ie:

webview.loadUrl( "javascript:window.location.reload( true )" );



回答2:


I had the same problem and fixed it using code:

private void reloadWebView() {
    postDelayed(new Runnable() {
        @Override
        public void run() {
            clearView();
            requestLayout();
        }
    }, 10);
}

Call it method when You have finished zooming. It will refresh web view and recalculate it size.




回答3:


You can use this:

myWebView.loadUrl("about:blank");



回答4:


private void reloadWebView() {
    // TODO Auto-generated method stub
    postDelayed(new Runnable() {
        @Override
        public void run() {
            clearView();
            reload();               
            myWebView.getSettings().setJavaScriptEnabled(true);
            requestLayout();
        }
    }, 10);
}


来源:https://stackoverflow.com/questions/12663083/webview-height-not-changing-after-resize-font-size

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