我已经开始使用 WebView 开发应用程序。实际上我正在使用 Webview 加载图像(我喜欢使用该类的内置缩放控件)。我可以成功加载图像,但我可以看到一些令人恼火的空白。我找不到删除它的方法。我的图像尺寸为 750 * 1000。我在下面附上了我的代码。
网页视图.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
图像查看器.java
package com.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class ImageViewer extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
String loadUrl = "file:///android_res/drawable/splash_001.jpg";
WebView image = (WebView) findViewById(R.id.webView);
image.clearView();
image.clearCache(true);
image.getSettings().setBuiltInZoomControls(true);
image.getSettings().setSupportZoom(true);
image.getSettings().setLoadWithOverviewMode(true);
image.getSettings().setUseWideViewPort(true);
image.loadUrl(loadUrl);
}
}
默认情况下webview正文中有一些边距/填充。如果您想删除该填充/边距,则覆盖正文tag并添加边距,例如:
<body style="margin: 0; padding: 0">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)