Canvas drawText 方法问题?

funnyone 2014-03-07 09:56:52
文档上是这样描述的。

/**
* Draw the text, with origin at (x,y), using the specified paint. The
* origin is interpreted based on the Align setting in the paint.
*
* @param text The text to be drawn
* @param x The x-coordinate of the origin of the text being drawn
* @param y The y-coordinate of the origin of the text being drawn
* @param paint The paint used for the text (e.g. color, size, style)
*/
public void drawText(String text, float x, float y, Paint paint) {
native_drawText(mNativeCanvas, text, 0, text.length(), x, y, paint.mBidiFlags,
paint.mNativePaint);
}


但是我测试后发现根本不对
float x, float y 指的是一个字体左上角的坐标。

主要代码是:

@Override
protected void onDraw(Canvas canvas) {
canvas.save();
float px = getWidth() / 2;
float py = getHeight() / 2;
float radius = Math.min(px, py);
canvas.drawCircle(px, py, radius, paint);

for (int i = 0; i <= 3; ++i) {
canvas.drawText(i + "", px - textWidth / 2, py - radius , textPaint);
canvas.rotate(90, px, py);
}
canvas.restore();
super.onDraw(canvas);
}

那个0,2不见啦这是什麽原因?

效果是:


...全文
166 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
儿大不由爷 2014-03-08
  • 打赏
  • 举报
回复
半径太大了 吧

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧