0

I have searched alot of this issue on google but unable to get any help.My question is how to get pixel position of android screen where the user has tapped?

muneikh
  • 2,067
  • 5
  • 25
  • 59

3 Answers3

3

this does the job.

public boolean onTouchEvent(MotionEvent event) {

        float x = event.getX();
        float y = event.getY();
Vinay W
  • 9,912
  • 8
  • 41
  • 47
  • Thanks, my onTouchEvent() not get called whenever I run my application. Are there any Listeners thats need to be setup? – muneikh Jul 11 '12 at 06:39
  • don't think so, see [this](http://android-coding.blogspot.in/2011/05/handle-ontouchevent-in-surfaceview.html) – Vinay W Jul 11 '12 at 06:44
1

This is probably what you're looking for: onTouchEvent

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Brad
  • 9,113
  • 10
  • 44
  • 68
0

Are you looking for getRawX and getRawY?

Jin35
  • 8,602
  • 3
  • 32
  • 52
  • What is the difference between getRawX or Y and getEventX and Y? – muneikh Jul 11 '12 at 06:38
  • 2
    `getRawX()` gives x-coordinate of event on screen, and `getX()` gives x-coordinate of event on view. So, `getX()` may be negative, if you move finger to left of your view. – Jin35 Jul 11 '12 at 07:13