Markdown
Markdown copied to clipboard
请问怎么设置在线的图片
public Drawable getDrawable(String source) {
Drawable drawable = BitmapUtil.LoadImageFromWebOperations(source);
drawable.setBounds(0, 0, about.getWidth() - about.getPaddingLeft() - about.getPaddingRight(), 400);
return drawable;
}
可以直接使用RichText来做,如果不想使用RichText的话可以按照下面的思路来做
public Drawable getDrawable(String src){
MyDrawable d=new MyDrawable();
// 异步加载图片
asyncLoadImage(new Callback(){
public void loaded(Bitmap b){
// 加载完成后把图片设置给壳子
d.setDrawable(new BitmapDrawable(b));
// 记得重新设置textView
textView.setText(textView.getText());
}
});
// 先返回一个壳子
return d;
}
class MyDrawable extends BitmapDrawable{
private Drawable d;
public void setDrawable(Drawable drawable) {
this.drawable = drawable;
}
@Override
public void draw(Canvas canvas) {
if (drawable != null ) {
drawable.draw(canvas);
}
}
}