fix:修复自定义ImageSpan加载图片回调更新View的线程问题

This commit is contained in:
max
2024-05-13 18:53:18 +08:00
parent 94f33e2fa7
commit bf3098d5c3

View File

@@ -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;
}
})