Created
October 15, 2015 22:39
-
-
Save asamaru7/0c3cd931e396cd0f8507 to your computer and use it in GitHub Desktop.
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
package net.asamaru.test; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.text.style.ReplacementSpan; | |
public class VerticalCenterSpan extends ReplacementSpan { | |
public VerticalCenterSpan() { | |
} | |
@Override | |
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { | |
int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)); | |
canvas.drawText(text, start, end, x, yPos, paint); | |
} | |
@Override | |
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { | |
return Math.round(paint.measureText(text, start, end)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment