xml文件中创建webview
<WebView
android:id="@+id/wv_explain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
<span style="white-space:pre"> </span>/>
在project下,main文件夹下新建assets文件,建web,最后images,在images里放需要加载的图片,在web中加入以该图片命名的html,其代码为:
<pre name="code" class="html"><html>
<head>
<title>explain</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices -->
<img src="images/explain.png" width="1080" height="3400" alt="">
<!-- End Save for Web Slices -->
</body>
</html>
最后在主代码里,申明webview,加入以下代码:
WebSetting

本文介绍了如何在Android Studio的项目中创建assets文件夹,存放图片,并通过WebView加载本地HTML文件显示这些图片。首先,在XML布局文件中添加WebView,然后在assets目录下创建web和images子目录,将图片放入images,HTML文件中引用图片路径。最后,主代码中声明并设置WebView加载包含图片链接的HTML。

2379

被折叠的 条评论
为什么被折叠?



