zl程序教程

您现在的位置是:首页 >  前端

当前栏目

省份封装代码

封装代码 省份
2023-09-27 14:20:56 时间

public class ProviceItem {
private Path path;

/**
* 绘制颜色
* */
private int drawColor;
public void setDrawColor(int drawColor){
this.drawColor = drawColor;
}

public ProviceItem(Path path) {
this.path = path;
}

public void drawItem(Canvas canvas, Paint paint,boolean isSelect){
if (isSelect){
//绘制内部颜色
paint.clearShadowLayer();
paint.setStrokeWidth(1);
paint.setStyle(Paint.Style.FILL);
paint.setColor(0xffff0000);
canvas.drawPath(path,paint);
//绘制边界
paint.setStyle(Paint.Style.STROKE);
paint.setColor(0xFFD0E8F4);
canvas.drawPath(path,paint);
}else {
paint.setStrokeWidth(2);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.FILL);
paint.setShadowLayer(8,0,0,0xffffff);
canvas.drawPath(path,paint);
//绘制边界
paint.clearShadowLayer();
paint.setColor(drawColor);
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(2);
canvas.drawPath(path,paint);
}
}

public boolean isTouch(float x,float y){//注意注意这块是来判断点击位置的 主要知识点Region
RectF rectF = new RectF(http://www.amjmh.com/v/);
path.computeBounds(rectF,true);
Region region = new Region();
region.setPath(path,new Region((int)rectF.left,(int)rectF.top,(int)rectF.right,(int) rectF.bottom));
return region.contains((int)x,(int)y);
}
}
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
布局使用代码如下:

<com.goodboy.mile.View.ChinaMapView
android:layout_width="match_parent"
android:layout_height="match_parent" />
---------------------