我想构建自定义 ImageSpan,它在获取数据开始时设置默认图片,并在获取完成时加载图片。
代码示例:
public class CustomImageSpan extends ImageSpan {
private Drawable mDrawable;
@Override
public Drawable getDrawable() {
if (mDrawable == null) {
mDrawable = defaultDrawable;
Futures.addCallback(
FetchImage.submit(
new FutureCallback<Image>() {
@Override
public void onSuccess(Image result) {
Bitmap bitmap = result.getBitmap();
mDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
//!Rerender span with new bitmap.
}
}, mExecutor);
}
return mDrawable;
}
如何通知 span 加载已完成,是时候获取新位图而不是默认位图了?