fix:修复自定义ImageSpan加载图片回调更新View的线程问题
This commit is contained in:
@@ -4,6 +4,7 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.widget.TextView;
|
||||
@@ -66,7 +67,16 @@ public class CustomAutoWidthImageSpan extends ImageSpan {
|
||||
if (textView == null) return true;
|
||||
CustomAutoWidthImageSpan.this.drawable = resource;
|
||||
CustomAutoWidthImageSpan.this.drawable.setBounds(0, 0, width, height);
|
||||
textView.setText(textView.getText());
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
textView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
textView.setText(textView.getText());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
textView.setText(textView.getText());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user