我的申请表中有几行。如果有人触摸了一条线,我必须突出显示触摸的线。我想如果我可以绘制一个浅色的透明矩形,而不是点击的线条颜色,那么它将被正确突出显示..所以有人能告诉我如何在Android画布上绘制透明矩形? 我的线条颜色是黑色。请看图片。提前谢谢。
答案 0 :(得分:2)
这将在画布上绘制绿色的50%透明矩形:
Paint myPaint = new Paint();
myPaint.setStyle(Paint.Style.FILL);
myPaint.setColor(Color.rgba(0, 256, 0, 128)); // green color with 50% transparency
// c is your canvas
c.drawRect(100, 100, 200, 200, myPaint);
答案 1 :(得分:1)
试试这种方式
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setColor(Color.RED);
mPaint.setStrokeWidth(3);
mPaint.setPathEffect(null);
canvas.drawRect(x, y, x + width, y + height, mPaint);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setColor(Color.WHITE);
mPaint.setStrokeWidth(3);
mPaint.setPathEffect(new DashPathEffect(new float[] { 5, 5 }, 5));
canvas.drawRect(x, y, x + width, y + height, mPaint);
答案 2 :(得分:1)
你可以用这个:
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.MAGENTA);
DashPathEffect dashPath =new DashPathEffect(new float[ ]{70,2}, 30);
paint.setPathEffect(dashPath);
paint.setStrokeWidth(80);
canvas.drawRect(30, 300 , 320, 300, paint);