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
  • 1,997
  • 5
  • 23
  • 58

3 Answers3

3

this does the job.

public boolean onTouchEvent(MotionEvent event) {

        float x = event.getX();
        float y = event.getY();
Vinay W
  • 9,583
  • 7
  • 36
  • 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
  • 125,853
  • 70
  • 238
  • 294
Brad
  • 8,965
  • 10
  • 41
  • 67
0

Are you looking for getRawX and getRawY?

Jin35
  • 8,582
  • 3
  • 31
  • 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