Reduce image height and width

I set Image Drawable as a SpannableString in a TextView, but the image comes out larger than the text, which looks weird. I need to reduce the size of the image so that it has the same height as the text:

Here is what I tried:

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); 
+5
source share
1 answer

You need to measure the height of the TextView and use it instead of the inner borders:

 int lineHeight = holder.temptext.getLineHeight(); drawable.setBounds(0, 0, lineHeight, lineHeight); 
+4
source

All Articles