简体   繁体   English

Android 中的 OnTouchListener

[英]OnTouchListener in Android

How can I get the X and Y Yadoes when the user touchs the screen at first and when you remove the finger from the screen.当用户首先触摸屏幕以及从屏幕上移开手指时,如何获得 X 和 Y Yadoes。 (First and coastal X coordinates when the user removes his finger as well as coordinates y) (用户移开手指时的第一和沿海 X 坐标以及坐标 y)

You have to override onTouchEvent like below.您必须像下面这样覆盖 onTouchEvent。 It will return X,Y.它将返回 X,Y。

  Override
    public boolean onTouchEvent(MotionEvent event)
    {
        int yourX = (int)event.getX();
        int yourY = (int)event.getY();

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
        }

        return false;
    }

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

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