Paint Touch track monitoring, mainly three kinds of, action_down,action_move,action_up
PublicBoolean ontouchevent (motioneventEvent){ intAction =Event. Getaction (); floatx =Event. GetX (); floaty =Event. GetY (); Switch(action) { CaseMotionEvent.ACTION_DOWN:mPath.moveTo (x, y); Break; CaseMotionEvent.ACTION_MOVE:mPath.quadTo (MPOSX, Mposy, x, y); Break; Casemotionevent.action_up://Mpath.reset (); Break; } //records the current coordinates of the current touch pointMPOSX =x; Mposy=y;return true;}
But the touch draw track has two effects, one is that the finger moves over, the trajectory appears, then set in the Action_up: in the action_up, draw the Cachecanvas.drawpath (path, paint);
PublicBoolean ontouchevent (motioneventEvent) { //TODO auto-generated Method Stub floatx =Event. GetX (); floaty =Event. GetY (); Switch(Event. Getaction ()) { Casemotionevent.action_down: {cur_x=x; Cur_y=y; Path.moveto (cur_x, cur_y); Ismoving=true; Break; } CaseMotionevent.action_move: {if(!ismoving) Break; //Two-time curve drawingpath.quadto (cur_x, cur_y, x, y); //Cachecanvas.drawpath (path, paint); //The following method seems to be the same as above//Path.lineto (x, y);cur_x =x; Cur_y=y; Break; } Casemotionevent.action_up: {//The mouse bounces to save the last stateCachecanvas.drawpath (path, paint); Path.reset (); Ismoving=false; Break; } }
The second is to show the drawing trajectory when touching, then set in Action_move: Cachecanvas.drawpath (path, paint);
PublicBoolean ontouchevent (motioneventEvent) { //TODO auto-generated Method Stub floatx =Event. GetX (); floaty =Event. GetY (); Switch(Event. Getaction ()) { Casemotionevent.action_down: {cur_x=x; Cur_y=y; Path.moveto (cur_x, cur_y); Ismoving=true; Break; } CaseMotionevent.action_move: {if(!ismoving) Break; //Two-time curve drawingpath.quadto (cur_x, cur_y, x, y); Cachecanvas.drawpath (path, paint); //The following method seems to be the same as above//Path.lineto (x, y);cur_x =x; Cur_y=y; Break; } Casemotionevent.action_up: {//The mouse bounces to save the last state//Cachecanvas.drawpath (path, paint);Path.reset (); Ismoving=false; Break; } }
Android----Paint Touch track monitor