Skip to content Skip to sidebar Skip to footer

ImageSpan Size Measurement With TextView And StaticLayout

I have a simple layout contains just one TextView. I wanna load an image into TextView using ImageSpan. Below method creates Spannable: private Spannable getImageSpannable(int draw

Solution 1:

I hope this method works

The following line of code

public void setContent() {

    SpannableStringBuilder content = new SpannableStringBuilder();
    content.append(getImageSpannable(R.drawable.my_image, 100, 260));
    content.append("\n");

    txtContent.setText(content);
}

Change to

public void setContent() {

    SpannableStringBuilder content = new SpannableStringBuilder();
    content.append(getImageSpannable(R.drawable.my_image, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    content.append("\n");

    txtContent.setText(content);
}

And resize "R.drawable.my_image" dimensions


Post a Comment for "ImageSpan Size Measurement With TextView And StaticLayout"