【问题标题】:I can't show image in webview我无法在 webview 中显示图像
【发布时间】:2013-12-12 10:14:59
【问题描述】:

iam 使用 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"); 

【问题讨论】:

  • 你需要将你的图片编码到html的src标签中,然后在webview中显示

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


【解决方案1】:

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

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

【讨论】:

  • 我的 xml 解析器中的图像不是本地的
  • 酷那么你需要做的是你hv制作一个字符串并将上面所有的html包含在上面并且需要更改图像名称并显示它就是这样
猜你喜欢
  • 1970-01-01
  • 2016-06-28
  • 2012-05-28
  • 2021-09-04
  • 2013-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多