我使用以下代码显示超过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>
提前致谢。
答案 0 :(得分:0)
将图像的路径更改为:
String html = "<h1>Header</h1><p>Custom HTML</p><p><img src=\"file:///android_asset/africa.png\"/></p>";
请确保您的项目资产文件夹下有非洲.png。