init name plate bg drawable width

This commit is contained in:
zoe
2020-07-29 22:48:12 +08:00
parent ab9b3a47d7
commit 33abe0e882

View File

@@ -75,6 +75,17 @@ public class CustomImageSpan extends ImageSpan {
this.url = url; this.url = url;
this.reference = new WeakReference<>(textView); this.reference = new WeakReference<>(textView);
this.height = SizeUtils.dp2px(textView.getContext(), 17); this.height = SizeUtils.dp2px(textView.getContext(), 17);
// width 不初始化会导致后面布局被截断
// 暂时先初始化为设计稿宽度
// 不是一个很好的处理办法,可以优化
final float ORI_HEIGHT = 34; // 原设计稿高度34px
float ratio = height / ORI_HEIGHT;
Paint paint = new Paint();
paint.setTextSize(ratio * 18);
float textWidth = paint.measureText(content);
this.width = (int) (textWidth + (40 + 4) * ratio + 16 * ratio);
this.drawable = defaultDrawable; this.drawable = defaultDrawable;
getDrawable().setBounds(0, 0, width, height); getDrawable().setBounds(0, 0, width, height);
loadPicAsyncWithHeight(); loadPicAsyncWithHeight();