简体   繁体   English

如何在Android中获取水龙头的X和Y坐标?

[英]How can I get the X, and Y, coordinates of a tap on a view in Android?

I'm working on a project and I need to get the x, and y coordinates of a tap on the Android canvas . 我正在做一个项目,我需要在Android canvas上获取水龙头的x和y坐标。

Example: When the user tap any spot on the canvas > 500px, a toast message pops up. 示例:当用户点击canvas > 500px的任何位置时,将弹出一条toast消息。

myView.setOnTouchListener(new OnTouchListener(){
     @Override
     public boolean onTouch(View v, MotionEvent event){

         Log.d("coords", event.getX() + " : " + event.getY();
         if(..){
             // Do stuff..
         }
     }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM