[英]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.