/
RoundMaskView.java
61 lines (52 loc) · 1.78 KB
/
RoundMaskView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.sky.hyh.customviewsamples.customview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import com.hyh.base_lib.utils.SizeUtils;
/**
* Created by hyh on 2018/9/29 18:10
* 高亮引导蒙层
*/
public class RoundMaskView extends View {
private PorterDuffXfermode mPorterDuffXfermode;
private Paint mPaint;
private RectF mRectF;
private int mRadius;
public RoundMaskView(Context context) {
this(context,null);
}
public RoundMaskView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPorterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
mRectF = new RectF();
mRadius = SizeUtils.dp2px(30);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mRectF.set(getPaddingLeft(),
getPaddingTop(),
getPaddingLeft() + w,
getPaddingTop() + h);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.saveLayer(mRectF, null, Canvas.ALL_SAVE_FLAG);
//绘制蒙层背景
canvas.drawColor(Color.parseColor("#99000000"));
//移动坐标系原点到屏幕中心
canvas.translate(getWidth()/2,getHeight()/2);
mPaint.setXfermode(mPorterDuffXfermode);
//绘制圆形高亮区域
canvas.drawCircle(0,0,mRadius,mPaint);
canvas.restore();
}
}