TextView 支持 html 图片显示

简介: 引用:http://woshao.com/article/697693b8b65e11e0a18f000c29fa3b3a/ 在TextView中显示HTML内容的方法如下所示: 1 TextView description=(TextView)findViewById(R.

引用:http://woshao.com/article/697693b8b65e11e0a18f000c29fa3b3a/

在TextView中显示HTML内容的方法如下所示:

1 TextView description=(TextView)findViewById(R.id.description);

2 description.setText(Html.fromHtml(item.getDescription()));

如果HTML中有图片的话,显示出来的图片会被一个小框取代,那么怎么样才能看到图片呢?查看了一下API,

android.text.Html还还有 另一个方法:

Html.fromHtml(String source,ImageGetter imageGetter,TagHandler tagHandler)


例:

ImageGetter imgGetter = new Html.ImageGetter() {
02         public Drawable getDrawable(String source) {
03             Drawable drawable = null;
04             Log.d("Image Path", source);
05             URL url;
06             try {
07                 url = new URL(source);
08                 drawable = Drawable.createFromStream(url.openStream(),"");
09             catch (Exception e) {
10                 return null;
11             }
12             drawable.setBounds(00, drawable.getIntrinsicWidth(), drawable
13                     .getIntrinsicHeight());
14             return drawable;
15         }
16     };
17 .........
18 TextView description=(TextView)findViewById(R.id.description);
19 description.setText(Html.fromHtml(item.getDescription(),imgGetter,null));
相关文章
|
5月前
html中设置背景图片不重复不平铺只显示一张图片
html中设置背景图片不重复不平铺只显示一张图片
146 0
|
17天前
|
移动开发
uni-app使用v-html输出富文本图片溢出解决
uni-app使用v-html输出富文本图片溢出解决
36 1
|
1月前
|
UED
12.使用HTML制作交互图片
12.使用HTML制作交互图片
18 0
|
1月前
|
Web App开发 前端开发 iOS开发
编程笔记 html5&css&js 008 HTML图片
编程笔记 html5&css&js 008 HTML图片
|
3月前
|
前端开发
html+css实现图片缓慢变大效果
html+css实现图片缓慢变大效果
34 0
|
8月前
HTML插入图片
HTML插入图片
81 0
|
3月前
解决html中图片自适应屏幕大小的问题
解决html中图片自适应屏幕大小的问题
|
4月前
html中img图片进行等比例缩放的实例代码
HTML中,要修改img元素定义的图片的大小,且是等比例缩放,不改变宽和高的比值,那么可以采用只设置img元素属性中width和height中的任何一个,不要同时设置两个即可实现img图片的等比例缩放效果。下面将通过两个实例来分别实现这两种方法。
83 1
|
4月前
|
前端开发 UED SEO
第二站:探索HTML中的图片标签
第二站:探索HTML中的图片标签
50 0
|
4月前
|
JavaScript 测试技术
html2canvas将document DOM节点转换为图片,并下载到本地
html2canvas将document DOM节点转换为图片,并下载到本地