3
3
import android .content .Context ;
4
4
import android .content .res .TypedArray ;
5
5
import android .graphics .Canvas ;
6
+ import android .graphics .Color ;
7
+ import android .graphics .Paint ;
6
8
import android .graphics .Rect ;
7
9
import android .util .AttributeSet ;
8
10
import android .view .MotionEvent ;
@@ -27,6 +29,7 @@ public class Split {
27
29
private int width = -1 , height = -1 ;
28
30
private List <Rect > mRects = new ArrayList <>();
29
31
private List <FRect > mFRects ;
32
+ private Rect mRect ;
30
33
private float mTouchX ;
31
34
private float mTouchY ;
32
35
@@ -97,6 +100,12 @@ protected void setOtherStyle(List<FRect> fRects) {
97
100
98
101
99
102
protected void onDraw (Canvas canvas ) {
103
+ if (mRect != null ) {
104
+ Paint paint = new Paint ();
105
+ paint .setColor (Color .BLUE );
106
+ paint .setAlpha (180 );
107
+ canvas .drawRect (mRect , paint );
108
+ }
100
109
}
101
110
102
111
private boolean isclick = false ;//是否正在执行点击事件
@@ -116,6 +125,7 @@ protected void onTouchEvent(MotionEvent event, View view) {
116
125
if (myRect .contains ((int ) mTouchX , (int ) mTouchY )) {
117
126
ischeckposition = true ;
118
127
position = i ;
128
+ mRect = myRect ;
119
129
view .invalidate ();
120
130
break ;
121
131
}
@@ -126,9 +136,9 @@ protected void onTouchEvent(MotionEvent event, View view) {
126
136
}
127
137
break ;
128
138
case MotionEvent .ACTION_UP :
129
- case MotionEvent .ACTION_POINTER_UP :
130
- case MotionEvent .ACTION_CANCEL :
131
139
isclick = false ;
140
+ mRect = null ;
141
+ view .invalidate ();
132
142
break ;
133
143
}
134
144
}
0 commit comments