简体   繁体   English

Android自定义圆圈视图逆背景色

[英]Android custom circle view inverse background color

I don't know how to call the outer-space of a circle... a mask or inverse-space? 我不知道如何称呼圆的外层空间...蒙版或逆空间? I hope you will understand what I'm trying to say by seeing the images. 希望您能通过查看图像来理解我要说的话。

Original image: 原始图片:

在此处输入图片说明

Custom view: 自定义视图:

在此处输入图片说明

As you can see, I want to apply that transparent-black color to my view, but I don't know where to start. 如您所见,我想将透明黑色应用于视图,但我不知道从哪里开始。

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);
    }

}

it achievable with the PorterDuff . 使用PorterDuff可以实现。 You can allocate a painter object, specifying the PorterDuff mode you need, and drawing the a circle with that paint, and accordingly to the mode you have to draw before or after the bitmap 您可以分配一个画家对象,指定所需的PorterDuff模式,并使用该绘画绘制一个圆,并相应于您必须在位图之前或之后绘制的模式

canvas.drawCircle(getWidth()/2, getWidth()/2, getWidth()/2, mPorterDuffPainter);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM