2010-09-03 4 views

Répondre

5

Remplacez onTouchEvent(MotionEvent event), puis appelez event.getX() et event.getY() pour obtenir les coordonnées de l'endroit où l'utilisateur a touché [ils seront flottants].

+0

merci! Cela a bien fonctionné! – tylercomp

0

son très simple pour obtenir la position des coordonnées où l'utilisateur a touché à l'écran.

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    // MotionEvent object holds X-Y values 
    if(event.getAction() == MotionEvent.ACTION_DOWN) { 
     String text = "You click at x = " + event.getX() + " and y = " + event.getY(); 
     Toast.makeText(this, text, Toast.LENGTH_LONG).show(); 
    } 

    return super.onTouchEvent(event); 
} 
Questions connexes