我必须绘制一个由圆圈内的三角形组成的自定义 shapeDrawable。我可以画圆和三角形,问题是我希望三角形是透明的,但是当我为绘制三角形的路径赋予透明颜色时,我会在三角形中看到圆圈的颜色,我不想有颜色圆形作为三角形的背景?这是我正在使用的代码:
@Override
protected void onDraw(Canvas canvas) {
Paint p = new Paint ();
int x = 1;
int y = 1;
Rect bounds = canvas.getClipBounds ();
p.setColor (color.getBackgroundColor());
p.setStyle(Style.FILL);
p.setStrokeWidth (0);
Path path = new Path();
Point p1 = new Point(bounds.centerX()-bounds.height()/4, bounds.centerY()-bounds.height()/4);
Point p2 = new Point(bounds.centerX()-bounds.height()/4, bounds.centerY()+bounds.height()/4);
Point p3 = new Point(bounds.centerX()+bounds.height()/4, bounds.centerY());
path.moveTo(p1.x, p1.y);
path.lineTo(p2.x, p2.y);
path.lineTo(p3.x, p3.y);
path.close();
Paint pTriang = new Paint();
pTriang.setColor(Color.TRANSPARENT);
pTriang.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
canvas.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.height()/2, p);
canvas.drawPath(path, pTriang );
}
顺便说一句,我正在覆盖 ImageView!