Created
February 19, 2015 11:55
-
-
Save hector6872/e2cb2d260bb783c99d28 to your computer and use it in GitHub Desktop.
Image Centered Span
This file contains hidden or 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