我是靠谱客的博主 生动美女,这篇文章主要介绍Android TextView 富文本加载实现,现在分享给大家,希望可以做个参考。

textView.settext(Html.fromHtml(text.toString(),new URLImageParser(textView),null))

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.changhong.hhys.utils.commom; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.text.Html; import android.view.View; import android.widget.TextView; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; /** * Created by g on 2016/10/5. */ public class URLImageParser implements Html.ImageGetter { TextView mTextView; public URLImageParser(TextView textView) { this.mTextView = textView; } @Override public Drawable getDrawable(String source) { final URLDrawable urlDrawable = new URLDrawable(); ImageLoader.getInstance().loadImage( source, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { urlDrawable.bitmap = loadedImage; urlDrawable.setBounds(0, 0, loadedImage.getWidth(), loadedImage.getHeight()); mTextView.invalidate(); mTextView.setText(mTextView.getText()); // 解决图文重叠 } }); return urlDrawable; } public class URLDrawable extends BitmapDrawable { protected Bitmap bitmap; @Override public void draw(Canvas canvas) { if (bitmap != null) { canvas.drawBitmap(bitmap, 0, 0, getPaint()); } } } }

最后

以上就是生动美女最近收集整理的关于Android TextView 富文本加载实现的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部