How to get width and height of a Webview in android

后端 未结 12 1121
长发绾君心
长发绾君心 2021-01-04 17:13

I want to determine the width and the height of the WebView. I have already tried it using:

webView.getWidth();
webView.getHeight();
         


        
12条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 17:45

    If you want to get the original height after loading content, you can use the below code. Though the code is deprecated, yet it works perfectly.

    webview.setPictureListener(new WebView.PictureListener() {
            @Override
            public void onNewPicture(WebView webView, @Nullable Picture picture) {
                int height = webview.getContentHeight();
                int height1 = webview.getMeasuredHeight();
                int height2 = webview.getHeight();
            }
        });
    

提交回复
热议问题