I need to get the touch begin position (X, Y) , touch move position and touch end position of the screen in android.
int x = (int)event. getX(); int y = (int)event. getY(); If you want the coordinates relative to the top left corner of the device screen, then use the raw values.
For Android device screen coordinates, below concept will work. Display mdisp = getWindowManager(). getDefaultDisplay(); Point mdispSize = new Point(); mdisp. getSize(mdispSize); int maxX = mdispSize.
@Override public boolean onTouchEvent(MotionEvent event) { int x = (int)event.getX(); int y = (int)event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: } return false; }
The three cases are so that you can react to different types of events, in this example tapping or dragging or lifting the finger again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With