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 height doesn't decrease. So there is empty space on the bottom remaining.
I've tried following trick:
articleContent.getSettings().setDefaultFontSize(fontSize);
RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.BELOW, subtitleTextView.getId());
articleContent.setLayoutParams(layoutParams);
But it didn't help. I know there is the way to fix it by recreating WebView with a code when I changing default font size, but in my situation I can not do like that. I need to keep webview, because there are some views bellow it, and I can not recreate them too.
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.
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.
Try this,
webview.setVisibility(View.GONE);
webview.setVisibility(View.VISIBLE);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With