求救各位大神,在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; }}