如何绘制非方形刻度线

How to draw non-square tick marks

在下图中,我正在尝试弄清楚如何绘制表盘上的刻度线。我知道如何画线,但我不确定如何像图片那样画 "tapered" 线。如何为 Android Wear 完成此操作?我想我需要创建一个 Path,但我不知道如何生成 Path 坐标。

要使用 Path,您需要执行以下操作:

Path path = new Path();

// Start at the top left corner
path.moveTo(screenCenterX - halfMarkerTopWidth, topMargin);

// Draw a line to the top right corner
path.lineTo(screenCenterX + halfMarkerTopWidth, topMargin);

// Draw a line to the bottom right corner
path.lineTo(screenCenterX + halfMarkerBottomWidth, topMargin + markerHeight);

// Draw a line to the bottom left corner
path.lineTo(screenCenterX - halfMarkerBottomWidth, topMargin + markerHeight);

// Close the Path (will automatically draw a line back to the top left corner)
path.close();

然后画你的路径 12 次,每次绘制之间旋转 canvas 30 度。

canvas.save();
for (int i = 0; i < 12; i++) {
    canvas.rotate(30, screenCenterX, screenCenterY);
    canvas.drawPath(path, paint);
}
canvas.restore();