I want to determine the width and the height of the WebView
. I have already tried it using:
webView.getWidth();
webView.getHeight();
but the resulting log always shows them to be 0.
I want to determine the width and the height of the WebView
. I have already tried it using:
webView.getWidth();
webView.getHeight();
but the resulting log always shows them to be 0.
Hmmm - I looked through the WevView source and I can see that internally they are using View#getWidth and View#getHeight here's one of the
WebView
's private methods:As noted in the comments you have to make sure you are measuring it after you assign the activity layout e.g.
setContentView(R.layout.mylayout);
You were probably checking for the sizes too soon, most likely in the
onCreate
. Instead, try this:you are checking size of webview too early. you can try this in following method
I had the same problem. I just put initWebView method in onWindowFocusChangedt.
You need the width and height of the WebView CONTENTS, after you loaded your HTML. YES you do, but there is no getContentWidth method (only a view port value), AND the getContentHeight() is inaccurate !
Answer: sub-class WebView: