3

I have a TextView, to which I'm setting SpannableString combining different Spans (ImageSpan, CalligraphyTypefaceSpan) showing icon-text pairs:

enter image description here

It works as I expect, but on the line break, the icon and the corresponding text are getting divided. I want it always to be displayed as one block. I was trying to add non-breakable space (  or \u00A0) between them, but it causes the icon to be drawn twice:

enter image description here

So, I think the solution may be to somehow combine these two spans in one block (span) and force the TextView to draw them together. But other solutions to my problem are welcome as well.

Georgiy Shur
  • 748
  • 1
  • 8
  • 19
  • tried ReplacementSpan? – pskink Apr 28 '16 at 20:58
  • Just took a quick look at it. It seems it allows to create custom span, but I thought there may be simpler solution. Anyway thanks, I'll try it. – Georgiy Shur Apr 29 '16 at 06:31
  • @pskink `ImageSpan` already is a `ReplacementSpan`, because it is a subclass of `DynamicDrawableSpan` which is a subclass of `ReplacementSpan`, so I'm not sure how that would help. – Rolf ツ Oct 13 '16 at 20:28
  • @Rolfツ because you can draw both the icon and the text in one `ReplacementSpan` – pskink Oct 13 '16 at 20:32
  • That could actually work for this example, but unfortunately doesn't offer a generic non-breaking ImageSpan solution. – Rolf ツ Oct 13 '16 at 20:34

0 Answers0