TextView设置行间距ImageSpan居中的问题

public class MyImageSpan extends ImageSpan {

    public MyImageSpan(Context context, Bitmap b) {
        super(context, b);
    }

    @Override
    public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end,
                     float x, int top, int y, int bottom, @NonNull Paint paint) {
        Drawable b = getDrawable();
        Paint.FontMetricsInt fm = paint.getFontMetricsInt();
        int transY = (y + fm.descent + y + fm.ascent) / 2
                - b.getBounds().bottom / 2;

        canvas.save();
        canvas.translate(x, transY);
        b.draw(canvas);
        canvas.restore();
    }
}

你可能感兴趣的:(TextView设置行间距ImageSpan居中的问题)