Skip to content

Instantly share code, notes, and snippets.

@hrules6872
Created February 19, 2015 11:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrules6872/e2cb2d260bb783c99d28 to your computer and use it in GitHub Desktop.
Save hrules6872/e2cb2d260bb783c99d28 to your computer and use it in GitHub Desktop.
Image Centered Span
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