Last active
December 5, 2017 14:29
-
-
Save efemoney/1262972c5e5bfd59d63598761d01badc to your computer and use it in GitHub Desktop.
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
public class HorizontalLineSpan extends ReplacementSpan { | |
private Context context; | |
public HorizontalLineSpan(Context context) { | |
this.context = context; | |
} | |
@Override | |
public int getSize(Paint paint, CharSequence text, | |
int start, int end, | |
Paint.FontMetricsInt fm) { | |
return 0; | |
} | |
@Override | |
public void draw(Canvas canvas, CharSequence text, | |
int start, int end, float x, | |
int top, int y, int bottom, Paint paint) { | |
Paint.FontMetricsInt fmi = paint.getFontMetricsInt(); | |
int height = fmi.descent - fmi.ascent; // set the drawable height to the height of the current font | |
Drawable b = getDrawable(canvas.getWidth(), height); | |
canvas.save(); | |
int transY = bottom - b.getBounds().bottom; | |
canvas.translate(x, transY); | |
b.draw(canvas); | |
canvas.restore(); | |
} | |
private Drawable getDrawable(int width, int height) { | |
// We copy the implementation of getCachedDrawable in DynamicDrawableSpan | |
Drawable d = getCachedDrawable(); | |
d.setBounds(0, 0, width, height); | |
return d; | |
} | |
public Drawable getDrawable() { | |
return new LineDrawable(context); | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment