Android查询可缩放Web图像-适合查看

Android查询可缩放Web图像-适合查看,android,android-webview,android-query,Android,Android Webview,Android Query,我正在使用将图像加载到webview中,因此我可以使用该特定视图附带的缩放功能 现在,我加载的图像比宽的图像高,因此,在我的布局中,正在被裁剪(看不到正在讨论的图像的底部) 我是否可以修改代码,强制加载的图像缩放以适应视图?文件上说 除ImageView外,WebView还可用于显示图像 以及Android内置的对WebView的缩放支持。图像将是 居中并填充webview的宽度或高度,具体取决于其位置 方向 所以我想我可能不走运了?下面是加载图像的相关代码行 aq.id(R.id.webvie

我正在使用将图像加载到webview中,因此我可以使用该特定视图附带的缩放功能

现在,我加载的图像比宽的图像高,因此,在我的布局中,正在被裁剪(看不到正在讨论的图像的底部)

我是否可以修改代码,强制加载的图像缩放以适应视图?文件上说

除ImageView外,WebView还可用于显示图像 以及Android内置的对WebView的缩放支持。图像将是 居中并填充webview的宽度或高度,具体取决于其位置 方向

所以我想我可能不走运了?下面是加载图像的相关代码行

aq.id(R.id.webview).progress(R.id.progressbar).webImage(imageUrl);
这是我们的行程

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
  </RelativeLayout>

好的。找到了一个适合我特定场景的解决方案,所以

因为我知道加载到webview中的图像的比例,所以我想我可以将webview调整到正确的比例,以确保它正确匹配可用空间。我将XML更新为这个

 <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical" >

        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>
…其中“1.28”值是我的图像的宽度和高度之间的比率(高度除以宽度)

因此,图像被添加到webview,视图被布局,然后这段代码开始使用,并收缩宽度,直到它足够小,可以使用适当的比率来适应可用的高度。新的LinearLayout使网络视图居中,以保持事物看起来整洁

@Override
public void onWindowFocusChanged(boolean hasFocus) {

    // need to set correct proportions of webview to match image
    super.onWindowFocusChanged(hasFocus);
    WebView mWrapper = (WebView) findViewById(R.id.webview);
    int w = mWrapper.getWidth();
    int h = mWrapper.getHeight();
    while ( w * 1.28 > h ) {
        w--;
    }
    LayoutParams params = new LinearLayout.LayoutParams( (int) w, LinearLayout.LayoutParams.FILL_PARENT );
    mWrapper.setLayoutParams(params);
}