异步加载图片:先返回一个LevelListDrawable,之后加载图片,获取到Bitmap之后转为Drawable,并设置到之前的LevelListDrawable中,更新level。这里要注意,要重新设置一下Textview的text,不然图片显示不出来。
public class HtmlTool {
public static SpannableStringBuilder fromHtml(String source, final TextView textView){
textView.setMovementMethod(LinkMovementMethod.getInstance());
Spanned spanned = Html.fromHtml(source, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
final LevelListDrawable drawable = new LevelListDrawable();
Ion.with(TumlodrApp.mContext)
.load(source)
.asBitmap()
.setCallback(new FutureCallback<Bitmap>() {
@Override
public void onCompleted(Exception e, Bitmap result) {
if(result != null) {
BitmapDrawable bitmapDrawable = new BitmapDrawable(result);
drawable.addLevel(1, 1, bitmapDrawable);
drawable.set