演示效果如下:
//写一个实体类
public class Circle {
public float x;
public float y;
public int r=100;
public int pointId;
int red;
int green;
int blue;
Random random=new Random();
public Circle(float x, float y, int pointId) {
this.x = x;
this.y = y;
this.pointId = pointId;
red=random.nextInt(255);
green=random.nextInt(255);
blue=random.nextInt(255);
}
public void drawSelf(Canvas canvas, Paint paint){
paint.setColor(Color.rgb(red,green,blue));
canvas.drawCircle(x,y,r,paint);
}
}
/**
* 1.多点触摸画圆
* 2.抬起手移除圆
* 3.圆可移动
* 4.设置圆的颜色
*/
public class MyView extends View{
List<Circle> circles=new ArrayL