Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get width and height of a Webview in android

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.

like image 491
mini Avatar asked Oct 23 '09 10:10

mini


Video Answer


1 Answers

You were probably checking for the sizes too soon, most likely in the onCreate. Instead, try this:

webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView webView, String url) {
                super.onPageFinished(webView, url);
                Log.i(TAG, findViewById(R.id.my_component).getWidth(););
            }
        });
like image 62
espinchi Avatar answered Sep 21 '22 01:09

espinchi