Android examples for android.graphics:Canvas
calculate Y When Text Align Center
import android.graphics.Paint; public class Main { public static float calcYWhenTextAlignCenter(int aCanvasHeight, Paint aPaint) { if (aPaint == null) { return 0;/*w ww .j ava 2 s .c o m*/ } final float fontHeight = aPaint.getFontMetrics().bottom - aPaint.getFontMetrics().top; return ((aCanvasHeight - fontHeight) / 2 - aPaint.getFontMetrics().top); } }