Created
August 8, 2017 09:55
-
-
Save TakuSemba/5a71eca8073f290ab96967a4b98bed8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CanvasView extends View { | |
private Paint backgroundPaint = new Paint(); | |
private Paint paint = new Paint(); | |
public CanvasView(Context context) { | |
super(context); | |
} | |
public CanvasView(Context context, @Nullable AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public CanvasView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
public void draw(Canvas canvas) { | |
super.draw(canvas); | |
setLayerType(View.LAYER_TYPE_HARDWARE, null); | |
// draw all | |
backgroundPaint.setColor(ContextCompat.getColor(getContext(), android.R.color.background_dark)); | |
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), backgroundPaint); | |
// hollow a cirlce out of the black brackgroud | |
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); | |
canvas.drawCircle(getWidth() / 2, getHeight() / 2, 250, paint); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment