0

I'm trying to add some images to a textview, and found out how to do that simple enough using Spannable String. Works fine, however, if I want to resize the image (either smaller than original, or larger than original), I can't seem to get it to resize.

There's some other similar questions that seem to answer this, however, trying to convert them to Kotlin, I'm unable to get anything to work.

How to display image in Android's TextView? Reduce ImageSpan height and width

This is what I have at this point:

    // build images/text together
    val is1 = ImageSpan (this, android.R.drawable.ic_menu_compass)
    val is2 = ImageSpan (this, android.R.drawable.ic_menu_compass)
    //is2.drawable.setBounds(500,500,1000,1000)
    is2.drawable.setBounds(0,0,txtInfo.lineHeight*4,txtInfo.lineHeight*4)
    val s = SpannableStringBuilder()
        .append("Test line 1")
        .append("\n")
        .append(" ", is1, 0)
        .append("\n")
        .append("Test line 2")
        .append("\n")
        .append(" ", is2, 0)
        .append("\n")
        .append("Test line 3")

    txtInfo.text = s

but both options using setBounds don't seem to result in any change. Ie the 2 images of the compass appear exact same size.

How to resize these images (either to fixed size or otherwise) in Kotlin ?

enter image description here

Ditto
  • 3,203
  • 1
  • 13
  • 28

0 Answers0