0

我有一个简单的应用程序,它从网络上提取某些图像并通过 WebView 显示它们,下方有按钮,上方有标题。起初,我遇到了图像下方不断有额外空白的问题,现在已解决。

作为参考,WebView 定义如下:

    <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>

这个相对布局在另一个布局中,我把它省略了。在活动中,我有以下内容:

        WebView img = (WebView) findViewById(R.id.webview);
        img.getSettings().setBuiltInZoomControls(true);
        img.getSettings().setSupportZoom(false);
        img.loadUrl(image);

现在到当前问题:

我正在提取和查看的图像具有不同的大小。为简单起见,让我们讨论两种尺寸 - X 和 Y,其中 X < Y。启动,尺寸 X 的图像按预期显示,点击按钮,按预期显示尺寸 Y 的图像,如果下一个图像尺寸为,则点击按钮X 再次显示,它会以额外的空白(总是在下方)填充到 Y 大小。对于许多大小为 X 的图像,它可能会保持这种状态,或者随机恢复正常。希望我把问题说清楚了。

我是否必须以某种方式明确重置界限?我做了相当多的谷歌搜索,但找不到问题。

提前致谢!

4

1 回答 1

0

好的,问题解决了。也许它将来也会对某人有所帮助。我在上面显示的 WebView 调用中添加了两个函数,即 clearView 和 clearCache:

    WebView img = (WebView) findViewById(R.id.webview);
    img.clearView();
    img.clearCache(true);
    img.getSettings().setBuiltInZoomControls(true);
    img.getSettings().setSupportZoom(false);
    img.loadUrl(image);

无论是一个还是另一个都没有帮助,只有两者的结合对我有用。对我来说感觉有点残酷,但有效。

于 2011-12-18T14:24:29.987 回答