Android, 绘制一个偏离中心的时钟
Android, draw clock with offset from center
我正在尝试使用 Android API:
实现此 WatchFace
这些是我用于时分秒的颜料:
secondsPaint.setAntiAlias(true);
secondsPaint.setColor(Color.RED);
secondsPaint.setStyle(Paint.Style.STROKE);
secondsPaint.setStrokeJoin(Paint.Join.ROUND);
secondsPaint.setStrokeWidth(3f);
secondsPaint.setAntiAlias(true);
minutesPaint.setColor(Color.WHITE);
minutesPaint.setStyle(Paint.Style.STROKE);
minutesPaint.setStrokeJoin(Paint.Join.ROUND);
minutesPaint.setStrokeWidth(4f);
hoursPaint.setAntiAlias(true);
hoursPaint.setColor(Color.WHITE);
hoursPaint.setStyle(Paint.Style.STROKE);
hoursPaint.setStrokeJoin(Paint.Join.ROUND);
hoursPaint.setStrokeWidth(5f);
我已经实现了以下代码来绘制背景、秒、分钟和小时:
// Background
canvas.drawBitmap(background, 0, 0, null);
然后我画小时和分钟
// Draw the minute and hour hands.
float minX = (float) Math.sin(minRot) * minLength;
float minY = (float) -Math.cos(minRot) * minLength;
canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, minutesPai
float hrX = (float) Math.sin(hrRot) * hrLength;
float hrY = (float) -Math.cos(hrRot) * hrLength;
canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, hoursPaint);
最后秒
// draw seconds
float secX = (float) Math.sin(secRot) * secLength;
float secY = (float) -Math.cos(secRot) * secLength;
canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, secondsPaint);
我需要:
- 在屏幕中间创建一个圆圈并移动小时,
分钟和秒与中心的几个像素像图片
显示。
- 让秒和分多一些"smooth"因为
抗锯齿已设置但未按预期工作
目前结果如下:
画圆就像使用drawCircle()
一样简单。
因此,肮脏的技巧可能是绘制白色的和另一个更大的(甚至可能是更小的)具有相同背景颜色以覆盖分钟和秒针的部分。
所以,在手之后绘制,这些圆圈将覆盖你想隐藏的部分。
一个非常便宜的技巧(不涉及其他三角函数)。
肯定有效。
您甚至可以使用图层列表可绘制对象覆盖在中心...;)
但我想 drawCircle() 非常简单。
我正在尝试使用 Android API:
实现此 WatchFace这些是我用于时分秒的颜料:
secondsPaint.setAntiAlias(true);
secondsPaint.setColor(Color.RED);
secondsPaint.setStyle(Paint.Style.STROKE);
secondsPaint.setStrokeJoin(Paint.Join.ROUND);
secondsPaint.setStrokeWidth(3f);
secondsPaint.setAntiAlias(true);
minutesPaint.setColor(Color.WHITE);
minutesPaint.setStyle(Paint.Style.STROKE);
minutesPaint.setStrokeJoin(Paint.Join.ROUND);
minutesPaint.setStrokeWidth(4f);
hoursPaint.setAntiAlias(true);
hoursPaint.setColor(Color.WHITE);
hoursPaint.setStyle(Paint.Style.STROKE);
hoursPaint.setStrokeJoin(Paint.Join.ROUND);
hoursPaint.setStrokeWidth(5f);
我已经实现了以下代码来绘制背景、秒、分钟和小时:
// Background
canvas.drawBitmap(background, 0, 0, null);
然后我画小时和分钟
// Draw the minute and hour hands.
float minX = (float) Math.sin(minRot) * minLength;
float minY = (float) -Math.cos(minRot) * minLength;
canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, minutesPai
float hrX = (float) Math.sin(hrRot) * hrLength;
float hrY = (float) -Math.cos(hrRot) * hrLength;
canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, hoursPaint);
最后秒
// draw seconds
float secX = (float) Math.sin(secRot) * secLength;
float secY = (float) -Math.cos(secRot) * secLength;
canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, secondsPaint);
我需要:
- 在屏幕中间创建一个圆圈并移动小时, 分钟和秒与中心的几个像素像图片 显示。
- 让秒和分多一些"smooth"因为 抗锯齿已设置但未按预期工作
目前结果如下:
画圆就像使用drawCircle()
一样简单。
因此,肮脏的技巧可能是绘制白色的和另一个更大的(甚至可能是更小的)具有相同背景颜色以覆盖分钟和秒针的部分。
所以,在手之后绘制,这些圆圈将覆盖你想隐藏的部分。
一个非常便宜的技巧(不涉及其他三角函数)。
肯定有效。
您甚至可以使用图层列表可绘制对象覆盖在中心...;)
但我想 drawCircle() 非常简单。