Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Android WebView Content Measuring
public class WebViewMeasuringActivity extends RelativeLayout {
public void loadHtml(String html)
WebView webView = (WebView) findViewById(;
webView.addJavascriptInterface(new WebViewResizer(), "WebViewResizer");
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView webView, String url) {
super.onPageFinished(view, url);
webView.loadData(html, mimeType, encoding);
private class WebViewResizer {
public void processHeight(String height) {
// height is in DP units. Convert it to PX if you are adjusting the WebView's height.
// height could be 0 if WebView visibility is Visibility.GONE.
// If changing the WebView height, do it on the main thread!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.