我无法在webview中显示图像

时间:2013-12-12 10:14:59

标签: android android-layout android-intent webview android-webview

我使用xml解析器,我的问题无法在webview上显示imageURL。 webview中的数据来自listview,但在listview中可以显示图像URL

这是我在webview中的代码

 static final String KEY_HEADLINE = "Headline";
 static final String KEY_ARTICLEDATE = "ArticleDate";
 static final String KEY_BODY = "Body";
 static final String KEY_IMAGEURL = "ImageURL";
 @Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webnews);

// getting intent data
Intent in = getIntent();
Bundle bun = in.getExtras();

 //Get XML values from previous intent
String headline = bun.getString(KEY_HEADLINE);
String date = bun.getString(KEY_ARTICLEDATE);
String Body = bun.getString(KEY_BODY);
String image = bun.getString(KEY_IMAGEURL);


Log.i("Result "+KEY_HEADLINE, headline);
WebView browser = (WebView)findViewById(R.id.webView1);
String HTML = "<div style='margin-top:5px; margin-left:5px; margin-right:5px;margin-  bottom;5px;'></div>
<div  style='font-family:Arial;font-size:14px;fontcolor:gray;'>"+date+"</div><div><strong style='font-family:Arial; font-size:24; margin-bottom:5;'>"+headline+"</strong></div>
<div><div style='float: margin-left:2px ;margin-right: 2px;margin-bottom: 1px; margin-top: 25px;'><center><img src="+image+" alt='' style='width:200px; height:127px; margin-bottom:20px;'</center></div>
<div style='line-height: 20px;font-size:16px; font-family:Arial'>"+Body+"</div></div></div>" ;
browser.loadData(HTML, "text/html", "utf-8"); 

1 个答案:

答案 0 :(得分:0)

webview接受html组件: 所以应该是这样的事情:

<html>
  <table>
    <tr>
      <td>
        <img src="monika.gif" width="50px" alt="Hello">
      </td>
    </tr>
  </table>
</html>