Android文本和图片未正确加载到webview中

时间:2012-11-23 05:52:48

标签: android html webview android-webview

我在将文字和图片加载到网页视图时遇到问题。当我尝试从本地资源文件夹加载html文件(包含文本和图像)时,首先加载文本,然后在text.for参考上加载图像,请参阅屏幕截图。我使用以下代码:

webView.loadUrl("file:///android_asset/Equest.html");

Html文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body{ font-family:Droid Sans;}
h2{font-family:Bookman old style; font-size:23px; color:#1f0909; font-weight:bold;}
h3{font-family:Bookman old style; font-size:16px; color:#1f0909; font-weight:bold;}
p{padding:5px 5px 5px 0px; margin:0px; line-height:20px;}
p{font-family:Droid Sans; font-weight: normal; font-size:18px; color:#1f0909;}
font
ul{padding-left:20px;}
ul li { line-height:22px;  padding:0px; font-family:Droid Sans; font-weight: normal; font-size:18px; color:#1f0909;}
img{padding-right:10px; vertical-align:middle;}

p strong{font-size:12px;}
strong{ font-size:20px;color:#1f0909;}
ul li div ul li{margin:0px 0px 5px 0px;}
    p a{ word-wrap:break-word; }p a{ word-wrap:break-word; }

.img-box{padding:5px;width:auto;height:auto; }
.img-box img{height:auto; width:100%; padding:0px; float:left; margin:0px 0px 3px 0px; }
div.transbox
  {
  width:auto;
  height:auto;
  margin:5px 5px;
  background-color:transparent;
  color:transparent;
  opacity:0.1;
  word-wrap:break-word;
  filter:alpha(opacity=10);
  }
</style>
</head>
<body>
<!--<h2 > Product Information - Equitape </h2>-->
<div class="img-box"><img src = "file:///android_res/drawable/equitape.PNG" /></div>
<div class="transbox">Moxidectin oral gel.</div>
<p> </p>
<ul>
  <li> Praziquantel oral paste. </li>
  <li> Single dose, flexible, targeted tapeworm control - ideal for treating horses not requiring a roundworm treatment. </li>
  <li> Palatable treatment, presented in compact easy to use dial-a-dose syringe. </li>
  <li> Licensed for horses - should only be used in mares during pregnancy or lactation after assessment of the benefits and risks by your veterinary surgeon. </li>
</ul>
<p>EQUITAPE is a registered trademark of Bayer AG. EQUITAPE contains praziquantel. </p>
<p>Advice on the use of this or alternative treatments must be sought from the medicine prescriber. Further information from Pfizer Animal Health, Pfizer Ltd, Walton Oaks, Dorking Road, Walton-on-the-Hill, Tadworth, Surrey KT20 7NS </p><p>POM-VPS</p> 
<p>
    <FORM>

        <a href="http://www.noahcompendium.co.uk/Pfizer_Limited/Equitape_90_mg_g_Oral_Gel_for_Horses/-32769.html">
        <img src = "file:///android_res/drawable/button_datasheet.png"/></a>
        <!--  <INPUT TYPE="button" value="See Datasheet" onclick="goToPage('' );" /> -->

    </FORM> 

    <!--Link to datasheet <a href="http://www.noahcompendium.co.uk/Pfizer_Limited/Equitape_90_mg_g_Oral_Gel_for_Horses/-32769.html"> http://www.noahcompendium.co.uk/Pfizer_Limited/Equitape_90_mg_g_Oral_Gel_for_Horses/-32769.html </a> --></p>
    <br />
    <br />
</body>
</html>

web view loading data

1 个答案:

答案 0 :(得分:-1)

使用下面的另一种方法从assets文件夹加载你的html文件,所以应用它。

WebView lWebView = (WebView)findViewById(R.id.webView);
  File lFile = new File(Environment.getExternalStorageDirectory() + "<FOLDER_PATH_TO_FILE>/<FILE_NAME>");
  lWebView.loadUrl("file:///" + lFile.getAbsolutePath());