ReplacementSpan's draw() method isn't called

后端 未结 7 1976
北海茫月
北海茫月 2021-02-08 03:26

I set background in string like that:

spanString.setSpan(new BackgroundColorSpan(color), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

But I would l

7条回答
  •  野性不改
    2021-02-08 04:15

    Even if you return the width of the span, the height of the span is 0 when the span covers the whole string. Therefore your span is actually there, with the specified width but the height is 0, therefore not drawn.

    You have to set the height of the span updating the values of the parameter Paint.FontMetricsInt fm for function getSize. Check the DynamicDrawable.getSize function as a reference to set the height by updating the FontMetrics values.

提交回复
热议问题