I have a simple app, which pulls certain images off the web and displays them via WebView with buttons below and a title above. At first, I had an issue of constantly having extra whitespace under the images, which is now resolved.
For reference, the WebView is defined as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/c"
android:layout_above="@id/b"
android:layout_below="@id/t"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:scaleType="centerInside"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true" />
</RelativeLayout>
This relative layout is within another one, I left it out.
In the Activity I have the following:
WebView img = (WebView) findViewById(R.id.webview);
img.getSettings().setBuiltInZoomControls(true);
img.getSettings().setSupportZoom(false);
img.loadUrl(image);
Now to the current issue:
The images I’m pulling and viewing have different sizes. For simplicity, let’s talk two sizes – X and Y, with X < Y. Launch, image of size X is displayed as expected, button tapped, image of size Y is displayed as expected, button tapped, if the next image is of size X again, it will be displayed with extra whitespace (always below) filling it up to size Y. It might stay that way for numerous images of size X or randomly go back to normal. Hope I made the issue clear.
Do I have to somehow explicitly reset the bounds? I did my fair share of googling, but can’t find the catch.
Thanks in advance!
Ok, issue resolved. Maybe it’ll help someone in the future as well. I added two functions to the WebView call shown above, namely, clearView and clearCache:
It didn’t help if it was either one or another, only the combination of the two worked for me. feels a little brutal to me, but works.