对于我正在开发的应用程序,我使用给定的坐标在 Canvas 上画一条线。问题是我需要在它旁边画一条虚线。由于坐标来自 API,我只能将这些坐标用于虚线。有什么办法可以做到这一点吗?我实在想不通。
我绘制当前线条的方式:
Path line = new Path();
boolean first = true;
for (CircleArea circle : mCircles) {
canv.drawCircle(circle.getDrawX(), circle.getDrawY(), mCircleRadius, mCirclePaint);
if(!first) {
line.lineTo(circle.getDrawX(), circle.getDrawY());
} else {
line.moveTo(circle.getDrawX(), circle.getDrawY());
}
first = false;
}
canv.drawPath(line, mLinePaint);
示例坐标:
- 50,50
- 75,75
- 100,75
- 150,10
- 170,10
- 170,75
- 160,75
最佳答案
此代码 fragment 可用于绘制破折号路径
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setPathEffect(new DashPathEffect(new float[] {20,20}, 0));
paint.setColor(Color.RED);
paint.setStrokeWidth(10);
canvas.drawPath(line, paint);
关于java - 在 Canvas 上画一条线,旁边再画一条虚线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43179653/