gpt4 book ai didi

Android Webview 使用物理单位 (cm/in)

转载 作者:行者123 更新时间:2023-11-28 12:57:45 24 4
gpt4 key购买 nike

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

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

我尝试使用视口(viewport)和比例,但未能以正确的物理单位显示我的图像。

这是我的 Activity 代码:

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>

你有什么想法吗?

最佳答案

我已经成功地将我的 webview 嵌入到具有固定大小和 ScrollView 的线性布局中!

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

关于Android Webview 使用物理单位 (cm/in),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16414154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com