2012-11-23 57 views
1

我在將文本和圖像加載到網絡視圖時遇到問題。當我嘗試從本地資源文件夾加載html文件(其中包含文本和圖像)時,文本首先加載,然後將圖像加載到text.for參考上查看屏幕截圖。我使用下面的代碼:Android文本和圖像未正確加載到webview中

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

使用下面這另一種方式來加載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()); 
+0

html文件駐留在本地「android-assets」文件夾中,但不在SD卡中。 – Ganesh

+0

好的,首先檢查你的html頁面,在任何瀏覽器中打開它,看看它是否有同樣的問題,如果是的話,那麼在webapage.html好的問題 –

+0

它在不同的瀏覽器中工作得很好。 – Ganesh