7

我将 Image Drawable 作为 SpannableString 设置为 TextView,但图像显示的比文本大,使其看起来很奇怪。我需要减小图像跨度的大小,使其与文本高度相同:

这是我尝试过的:

drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

SpannableStringBuilder builder = new SpannableStringBuilder(holder.temptext.getText());
builder.setSpan(new ImageSpan(drawable), selectionCursor - ":)".length(), selectionCursor, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.temptext.setText(builder);
holder.temptext.setSelection(selectionCursor);

holder.caption.setText(builder);
4

1 回答 1

10

您需要测量您TextView的高度并使用它而不是内在界限:

int lineHeight = holder.temptext.getLineHeight();

drawable.setBounds(0, 0, lineHeight, lineHeight);
于 2015-09-07T23:27:05.280 回答