我正在使用以下代码显示超过 1,000x1,000 的图像,存储在我项目的 assets 文件夹中。要启用缩放控件,我想在 WebView 中显示它。
我的代码:
public class ImageActivity extends Activity {
String html_data;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadHTML();
}
public void loadHTML() {
final String mimeType = "text/html";
final String encoding = "utf-8";
final String html = "<h1>Header</h1><p>Custom HTML</p><p><img src=\\"
+ "file:///android_asset/africa.png\\/></p>";
WebView wv = (WebView) findViewById(R.id.mapview);
wv.loadDataWithBaseURL("fake://not/needed", html, mimeType, encoding,"");
}
}
还有我的 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
提前致谢。