@Override
protected void onDraw(Canvas canvas) {
Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG);
// フォントの高さ
foreground.setTextSize(height * 0.75f);
// アスペクト比
foreground.setTextScaleX(width / height);
foreground.setTextAlign(Paint.Align.CENTER);
FontMetrics fm = foreground.getFontMetrics();
float x = width / 2;
float y = height / 2 - (fm.ascent + fm.descent) / 2;
canvas.drawText("Hello!", 100, 100, foreground);
}
public float getFontMetrics (Paint.FontMetrics metrics)
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it.
public float ascent
The recommended distance above the baseline for singled spaced text.
public float descent
The recommended distance below the baseline for singled spaced text.
More...
0 件のコメント:
コメントを投稿