I have webview with layout_height = \"wrap_content\". If I increase default font size, then webview height increases too. But if I decrease default font size, then webview h
The only solution I have found that actually works, is in the com.android.email client that comes with the Android Open Source Project. There, they have a RigidWebView which works with the wrap_content and will resize accordingly when the content changes. Source code for this can be found here:
https://android.googlesource.com/platform/packages/apps/Email/+/c19c1226da4a32e49e81c202478384f0348bcfef/src/com/android/email/view/RigidWebView.java
You'll need the Clock and Throttle classes that come with it, but with minor changes to the code, you can make it so it works in your app. Then anywhere where you would normally define a WebView, you can use RigidWebView instead.
Just add this
LinearLayout.LayoutParams wv_l = new
LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
wv.setLayoutParams(wv_l);
Try this,
webview.setVisibility(View.GONE);
webview.setVisibility(View.VISIBLE);
try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview1"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
This issue should be fixed in the KitKat WebView.
For WebView versions before KitKat there aren't any good workarounds I know of. Altering the width of the WebView should force a height recalculation but it might also lead to visual glitches.
I think that temporarily forcing a height of 0 and then flipping it back to wrap_contents should get rid of the excess padding too.
The issue is referenced Android's issue tracker here:
https://code.google.com/p/android/issues/detail?id=18726
If what you really want is a WebView wrapping your content it looks like the only work-around at the moment is to create a new WebView every time your content changes (which may not be acceptable when targeting low memory devices). It is the solution I have adopted anyway.