OnTouchEvent, ontouchevent used
Create a "MyView" Class
Package onTouchEvent; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. view. motionEvent; import android. view. view; public class MyView extends View {private int textX = 20, textY = 20; public MyView (Context context) {super (context); setFocusable (true ); // TODO Auto-generated constructor stub} // brush onDraw method @ Override protected void onDraw (Canvas canvas) {// TODO Auto-generated method stub super. onDraw (canvas); // initialize Paint paint = new Paint (); // set the color of paint. setColor (Color. GREEN); // set the font size to paint. setTextSize (50); // write the text canvas on the canvas. drawText ("Android", textX, textY, paint) ;}@ Override public boolean onTouchEvent (MotionEvent event) {// TODO Auto-generated method stub // obtain the X coordinate assignment of the user's finger touch screen and the X coordinate textX = (int) event of the text. getX (); // obtain the Y coordinate assignment of the user's finger touch screen and the text's Y coordinate textY = (int) event. getY (); // re-paint the cloth invalidate (); return true ;}}
In MainActivity, set setContentView to the current MyView, that is
setContentView(new MyView(this));
Run the following command: