How to getContentHeight when using loadData?

I need to get the height of my web view, which is loaded with static content, but the return height is always zero.

I initially thought this was because the webview did not load when requesting height, so I tried setting it to OnPageFinished through the webview client. This works when loading a page from the Internet, but not when downloading local content.

String html = "<html><head><title>Test</title></head><body><p>Insert content here</p></body></html>"; qWebView = (WebView) findViewById(R.id.webView1); qWebView.loadDataWithBaseURL(null, html, "text/html", "utf-8", null); qWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { int height = qWebView.getContentHeight(); Toast.makeText(WebviewHeightTestActivity.this, String.valueOf(height), Toast.LENGTH_SHORT).show(); } }); 

.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <WebView android:id="@+id/webView1" android:layout_width="match_parent" android:layout_height="wrap_content"></WebView> 

+4
source share

All Articles