0

我想在具有定义的宽度和高度的 web 视图中显示图像。

当我将我的 html 设置为:<img src='img.png' width='100%' height='100cm' /> 显示时:高度永远不会达到 100 厘米或我选择的任何值。

我尝试使用视口和比例,但没有设法让我的图像显示在正确的物理单位中。

这是我的活动代码:

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class myActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ruler);
        WebView web = (WebView) findViewById(R.id.webview);
        String url = "image.png";

        String imgSrcHtml = "<html><img src='" + url
                + "' width='100%' height='100cm' /></html>";
        web.loadDataWithBaseURL("file:///android_asset/", imgSrcHtml,
                "text/html", "UTF-8", null);
    }
}

和布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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" />


</RelativeLayout>

你有什么想法吗?

4

1 回答 1

0

我已经设法将我的 webview 嵌入到具有固定大小和滚动视图的线性布局中!

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="1000mm" >

        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="1000mm"
            android:fillViewport="true"
            android:text="@string/hello_world" />
    </LinearLayout>
</ScrollView>

于 2013-05-07T11:29:47.477 回答