ReplacementSpan's draw() method isn't called

后端 未结 7 2016
北海茫月
北海茫月 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

    In method getSize() the Paint.FontMetricsInt fm must be recalculated based on paint FontMetricsInt:

    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        width = Math.round(paint.measureText(text, start, end));
        Paint.FontMetricsInt metrics = paint.getFontMetricsInt();
        if (fm != null) {
            fm.top = metrics.top;
            fm.ascent = metrics.ascent;
            fm.descent = metrics.descent;
    
            fm.bottom = metrics.bottom;
        }
        return width;
    }
    

提交回复
热议问题