居中绘制文字 public void drawTextCenter(Canvas canvas, Rect rect, String text, Paint paint) { Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt(); float baseline = (rect.bottom + rect.top - fontMetrics.bottom - fontMetrics.to
public void drawTextCenter(Canvas canvas, Rect rect, String text, Paint paint) { Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt(); float baseline = (rect.bottom + rect.top - fontMetrics.bottom - fontMetrics.top) / 2; paint.setTextAlign(Paint.Align.CENTER); canvas.drawText(text, rect.centerX(), baseline, paint); }