如何像这样在弧的末端画一条线?
这是我当前用来绘制弧线的代码
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
canvasWidth = MeasureSpec.getSize(widthMeasureSpec);
canvasHeight = MeasureSpec.getSize(heightMeasureSpec);
padding = strokeWidth * 0.9f;
arcAngle = 360 * 0.8f;
rectF.set(padding, padding, canvasWidth - padding, canvasHeight - padding);
arcRadius = (canvasWidth - padding) / 2f;
arcBottomHeight = arcRadius * (float) (1 - Math.cos(angle / 180 * Math.PI));
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float startAngle = 270 - arcAngle / 2f;
float finishedSweepAngle = progress / (float) getMax() * arcAngle;
float finishedStartAngle = startAngle;
canvas.drawArc(rectF, startAngle, arcAngle, false, unfinishedPaint);
canvas.drawArc(rectF, finishedStartAngle, finishedSweepAngle, false, finishedPaint);
}
这会在彼此之上绘制2个圆弧,彩色圆弧(finishedPaint)表示进度。
我想使用canvas.drawLine()在圆弧的末端绘制直线,但是不确定如何获取坐标以指定直线的起点和终点。
答案 0 :(得分:1)
使用触发。您知道圆弧的半径及其结束的角度。 x是radius*sin(endangle)+xcenter
,y是radius*cos(endangle)+ycenter
。然后以相同的角度画线。