[英]Android custom circle view inverse background color
我不知道如何称呼圆的外层空间...蒙版或逆空间? 希望您能通过查看图像来理解我要说的话。
原始图片:
自定义视图:
如您所见,我想将透明黑色应用于视图,但我不知道从哪里开始。
public class MaskView extends View {
private int mBackgroundColor;
public MaskView(Context context) {
super(context);
init();
}
public MaskView(Context context, AttributeSet set) {
super(context, set);
init();
}
public MaskView(Context context, AttributeSet set, int defStyle) {
super(context, set, defStyle);
init();
}
private void init() {
mBackgroundColor = Color.parseColor("#AA000000");
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(mBackgroundColor);
}
}
使用PorterDuff可以实现。 您可以分配一个画家对象,指定所需的PorterDuff模式,并使用该绘画绘制一个圆,并相应于您必须在位图之前或之后绘制的模式
canvas.drawCircle(getWidth()/2, getWidth()/2, getWidth()/2, mPorterDuffPainter);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.