当前位置 : 主页 > 编程语言 > c++ >

Android 文字绘制

来源:互联网 收集:自由互联 发布时间:2021-07-03
居中绘制文字 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);
}
网友评论