简体   繁体   English

Android使用Paint绘制带有两种不同颜色的虚线

[英]Android Using Paint to draw dashed line with two different colors

I want to draw a dashed line with two colors. 我想用两种颜色画一条虚线。 I would like the line to alternate between red and white on even intervals. 我希望该行以相等的间隔在红色和白色之间交替。 What I have so far works pretty well, but the space between the dashes it transparent. 到目前为止,我的作品效果很好,但虚线之间的空间却是透明的。 That is what I am trying to change. 那就是我想要改变的。 My work so far: 到目前为止我的工作:

  Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  paint.setColor(Color.parseColor("#ED1C24"));
  paint.setStyle(Paint.Style.STROKE);
  paint.setPathEffect(new DashPathEffect(new float[] {10,10}, 0)); 

Thanks all!! 谢谢大家!

Try creating two paints with two colours and draw your line two times with different paints where the first one is not dashed while the second one on top is. 尝试创建两种具有两种颜色的绘画,并用不同的绘画绘制两次线条,其中第一种不虚线,而第二种在顶部。

If you want transparent spaces inbetween dashes then adjust dashed effect and try changing offset like: 如果要在破折号之间使用透明空格,请调整虚线效果,然后尝试更改偏移量,例如:

paint.setPathEffect(new DashPathEffect(new float[] {10,10}, 0)); 
paint2.setPathEffect(new DashPathEffect(new float[] {5,15}, 15)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM