数字的基线在哪里?
where are the numbers ' baseline?
我是这样研究应用程序的, .
/**
* draw the hour text (12、3、6、9)
* draw the arc
*/
private void drawTimeText() {
//draw the hour text
String timeText = "12";
mTextPaint.getTextBounds(timeText, 0, timeText.length(), mTextRect);
int textLargeWidth = mTextRect.width();//两位数字的宽
mCanvas.drawText("12", getWidth() / 2 - textLargeWidth / 2, mPaddingTop + mTextRect.height(), mTextPaint);
timeText = "3";
mTextPaint.getTextBounds(timeText, 0, timeText.length(), mTextRect);
int textSmallWidth = mTextRect.width();//一位数字的宽
mCanvas.drawText("3", getWidth() - mPaddingRight - mTextRect.height() / 2 - textSmallWidth / 2,
getHeight() / 2 + mTextRect.height() / 2, mTextPaint);
mCanvas.drawText("6", getWidth() / 2 - textSmallWidth / 2, getHeight() - mPaddingBottom, mTextPaint);
mCanvas.drawText("9", mPaddingLeft + mTextRect.height() / 2 - textSmallWidth / 2,
getHeight() / 2 + mTextRect.height() / 2, mTextPaint);
//draw the arc
mCircleRectF.set(mPaddingLeft + mTextRect.height() / 2 + mCircleStrokeWidth / 2,
mPaddingTop + mTextRect.height() / 2 + mCircleStrokeWidth / 2,
getWidth() - mPaddingRight - mTextRect.height() / 2 + mCircleStrokeWidth / 2,
getHeight() - mPaddingBottom - mTextRect.height() / 2 + mCircleStrokeWidth / 2);
for (int i = 0; i < 4; i++) {
mCanvas.drawArc(mCircleRectF, 5 + 90 * i, 80, false, mCirclePaint);
}
我不知道什么时候画小时文字“3”,
mCanvas.drawText("3", getWidth() - mPaddingRight - mTextRect.height() / 2 - textSmallWidth / 2,
getHeight() / 2 + mTextRect.height() / 2, mTextPaint);
使用canvas.drawText(),
void drawText (String text,
int start,
int end,
float x,
float y,
Paint paint)
"y"表示数字的基线,我不知道数字的基线规则,比如“3”,数字的基线在哪里?我搜索 google "baseline",但它只是关于英文字母基线,与数字基线无关。
据我所知,数字的 baseline 与字母的相同。大多数字体的数字都位于基线,但有些会延伸到基线以下,就像大多数字体中的 'g' 或 'j' 一样(某些 'old style' 或 'script' 字体就是一个很好的例子)......
这里的虚线是基线。
不要忘记,当您将 y 坐标发送到 drawText 方法时,它期望 baseline 和 not 的顶部那些角色。
希望这有帮助。
我是这样研究应用程序的,
/**
* draw the hour text (12、3、6、9)
* draw the arc
*/
private void drawTimeText() {
//draw the hour text
String timeText = "12";
mTextPaint.getTextBounds(timeText, 0, timeText.length(), mTextRect);
int textLargeWidth = mTextRect.width();//两位数字的宽
mCanvas.drawText("12", getWidth() / 2 - textLargeWidth / 2, mPaddingTop + mTextRect.height(), mTextPaint);
timeText = "3";
mTextPaint.getTextBounds(timeText, 0, timeText.length(), mTextRect);
int textSmallWidth = mTextRect.width();//一位数字的宽
mCanvas.drawText("3", getWidth() - mPaddingRight - mTextRect.height() / 2 - textSmallWidth / 2,
getHeight() / 2 + mTextRect.height() / 2, mTextPaint);
mCanvas.drawText("6", getWidth() / 2 - textSmallWidth / 2, getHeight() - mPaddingBottom, mTextPaint);
mCanvas.drawText("9", mPaddingLeft + mTextRect.height() / 2 - textSmallWidth / 2,
getHeight() / 2 + mTextRect.height() / 2, mTextPaint);
//draw the arc
mCircleRectF.set(mPaddingLeft + mTextRect.height() / 2 + mCircleStrokeWidth / 2,
mPaddingTop + mTextRect.height() / 2 + mCircleStrokeWidth / 2,
getWidth() - mPaddingRight - mTextRect.height() / 2 + mCircleStrokeWidth / 2,
getHeight() - mPaddingBottom - mTextRect.height() / 2 + mCircleStrokeWidth / 2);
for (int i = 0; i < 4; i++) {
mCanvas.drawArc(mCircleRectF, 5 + 90 * i, 80, false, mCirclePaint);
}
我不知道什么时候画小时文字“3”,
mCanvas.drawText("3", getWidth() - mPaddingRight - mTextRect.height() / 2 - textSmallWidth / 2,
getHeight() / 2 + mTextRect.height() / 2, mTextPaint);
使用canvas.drawText(),
void drawText (String text,
int start,
int end,
float x,
float y,
Paint paint)
"y"表示数字的基线,我不知道数字的基线规则,比如“3”,数字的基线在哪里?我搜索 google "baseline",但它只是关于英文字母基线,与数字基线无关。
据我所知,数字的 baseline 与字母的相同。大多数字体的数字都位于基线,但有些会延伸到基线以下,就像大多数字体中的 'g' 或 'j' 一样(某些 'old style' 或 'script' 字体就是一个很好的例子)......
这里的虚线是基线。
不要忘记,当您将 y 坐标发送到 drawText 方法时,它期望 baseline 和 not 的顶部那些角色。 希望这有帮助。