MyEyeView.java
1.81 KB
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
62
63
64
65
66
67
68
69
70
71
package com.share.mvpsdk.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Shader;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by ToaHanDong on 2018/2/7.
*/
public class MyEyeView extends View {
Paint myPaint;
int mypaintWidth=2;
int centerLeft=0,centerTop=0,centerRight=0,centerBottom=0;
public MyEyeView(Context context) {
super(context);
init(context);
}
public MyEyeView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MyEyeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
while (centerLeft>0){
centerLeft-=10;
centerTop-=10;
centerRight+=10;
centerBottom+=10;
canvas.drawRect(centerLeft,centerTop,centerRight,centerBottom,myPaint);
}
}
private void init(Context context) {
myPaint=new Paint();
myPaint.setColor(Color.WHITE);
myPaint.setAntiAlias(true);
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeWidth(mypaintWidth);
// myPaint.setShader(new Shader());
}
public void setMyPaintWidth(int paintWidth){
mypaintWidth=paintWidth;
}
public void setIndexPoint(int centerLeft,int centerTop,int centerRight,int centerBottom){
this.centerLeft=centerLeft;
this.centerTop=centerTop;
this.centerRight=centerRight;
this.centerBottom=centerBottom;
invalidate();
}
}