简体   繁体   中英

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. (First and coastal X coordinates when the user removes his finger as well as coordinates y)

You have to override onTouchEvent like below. It will return 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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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