当前位置: 代码迷 >> Eclipse >> 触碰屏幕,生成圆
  详细解决方案

触碰屏幕,生成圆

热度:77   发布时间:2016-04-23 12:26:51.0
求助:触碰屏幕,生成圆
求教各位大神,如何在android手机上实现下列功能:
手指触碰屏幕时,触碰的位置生成一个圆
生成圆的个数和触碰的次数有关,即触碰一次生成一个。

请大神指教。。。。

------解决方案--------------------
Java code
public class Circle extends View {    private List<Temp> temps = new ArrayList<Temp>();    private Paint paint;    public Circle(Context context) {        super(context);        setBackgroundColor(Color.WHITE);        paint = new Paint();        paint.setAntiAlias(true);        paint.setColor(Color.RED);        paint.setStyle(Style.STROKE);    }        @Override    protected void onDraw(Canvas canvas) {        for(Temp t : temps){            canvas.drawCircle(t.x, t.y, 10, paint);        }    }        class Temp{        public float x,y;        public Temp(float x,float y) {            this.x = x;            this.y = y;        }    }        @Override    public boolean onTouchEvent(MotionEvent event) {        if(event.getAction() == MotionEvent.ACTION_DOWN){            temps.add(new Temp(event.getX(),event.getY()));            postInvalidate();        }        return true;    }}
  相关解决方案