我试图画一个箭头,但我得到了一个非常奇怪的结果。这就是它的样子,问题很清楚 - 重叠部分。
int radius = 100; //Radius of blue circle to the right
Path leftArrow = new Path();
Paint leftArrowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
leftArrowPaint.setStyle(Paint.Style.STROKE);
leftArrowPaint.setColor(ContextCompat.getColor(getContext(), R.color.buttonText));
leftArrowPaint.setAlpha(80);
leftArrowPaint.setStrokeWidth(8);
在绘制方法中:
//Start point
leftArrow.moveTo(touchX-(radius+5), (int)touchY);
//Line to left
leftArrow.lineTo(touchX-(radius+60), (int)touchY);
//Line up
leftArrow.lineTo(touchX-(radius+30), (int)touchY-30);
//Move back to the middle
leftArrow.moveTo(touchX-(radius+60), (int)touchY);
//Line down
leftArrow.lineTo(touchX-(radius+30), (int)touchY+30);
canvas.drawPath(leftArrow, leftArrowPaint);
leftArrow.reset();
好的,我知道这对你来说太晚了,但无论如何我都会回答,以防有人遇到同样的问题。
需要指定"画图"的"联接"属性。https://developer.android.com/reference/android/graphics/Paint.Join.html
leftArrowPaint.setStrokeJoin(Paint.Join.BEVEL);
你也可以使用 Paint.Join.ROUND
,取决于什么更适合你。