The task is as follows: there is a background image on top of it is necessary to impose a semi-transparent background in the center of which is completely transparent circle. In this case, the background image - this shows a map with the current coordinates. Ie card should live their lives. A top of the card get something in the form of a semi-transparent film cut a circle in the center. Have the following code:
public class CircleView extends View {
private Paint srcPaint;
private Paint dstPaint;
public CircleView(Context context) {
this(context, null, 0);
}
public CircleView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CircleView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
float centerX = width / 2;
float centerY = height / 2;
float circleRadius = Math.min(width, height) / 5;
canvas.drawRect(0, 0, width, height, dstPaint);
canvas.drawCircle(centerX, centerY, circleRadius, srcPaint);
}
private void init() {
srcPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
srcPaint.setColor(Color.WHITE);
srcPaint.setStyle(Paint.Style.FILL);
srcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
dstPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
dstPaint.setColor(Color.argb(221, 255, 217, 32));
dstPaint.setStyle(Paint.Style.FILL);
}
}
But instead of the transparent area turns opaque black circle. What has been done wrong or what is missing?