Image Centered Span
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageCenteredSpan extends ImageSpan { | |
public ImageCenteredSpan(Drawable d) { | |
super(d); | |
} | |
@Override | |
public void draw(Canvas canvas, CharSequence text, | |
int start, int end, float x, | |
int top, int y, int bottom, Paint paint) { | |
Drawable b = getDrawable(); | |
canvas.save(); | |
int transY = bottom - b.getBounds().bottom; | |
transY -= paint.getFontMetricsInt().descent / 2; | |
canvas.translate(x, transY); | |
b.draw(canvas); | |
canvas.restore(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment