我的应用程序中有几行。如果有人触摸一条线,我必须突出显示所触摸的线。我想如果我可以用浅色绘制一个透明矩形,而不是单击的线条颜色,那么它将正确突出显示。那么有人可以告诉我如何在 Android 画布上绘制一个透明矩形吗?我的线条颜色是黑色。请看图片。
问问题
774 次
3 回答
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);
于 2013-09-10T08:19:14.323 回答
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);
于 2013-09-10T09:06:43.073 回答
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);
于 2013-09-10T08:12:39.267 回答