Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Touch position in android?

Tags:

android

I need to get the touch begin position (X, Y) , touch move position and touch end position of the screen in android.

like image 830
Alex Avatar asked Aug 13 '10 12:08

Alex


People also ask

How to get touch position Android Studio?

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.

How to get screen coordinates in Android?

For Android device screen coordinates, below concept will work. Display mdisp = getWindowManager(). getDefaultDisplay(); Point mdispSize = new Point(); mdisp. getSize(mdispSize); int maxX = mdispSize.


1 Answers

@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.

like image 177
dbrettschneider Avatar answered Sep 22 '22 15:09

dbrettschneider