开发者

Listening for when a gesture occurs on a specific object on screen

I will have several objects on my canvas at once and need to detect over which one the user performed a gesture. The only way I can thin开发者_如何学Ck of is splitting the screen up in to many views and listening in each but this isnt very efficient so has anyone a better way, preferably using seperate gesturedetectors that belong to each object individually?

I will be so so so grateful if someone can help me as I've been tearing my hair out trying to solve this all day


If you are tracking the position/hitbox of your objects on the canvas you can compare that to the RawX and RawY values in the MotionEvent.


  @Override
        public boolean onDoubleTap(MotionEvent e) {
            float e_x = e.getRawX();
            float e_y = e.getRawY();
            if(e_x > 100 && e_x < 200 && e_y > 400 && e_y < 600){
            // do something
            }
            return true ;
        }

This is what i did, just check for coordinates

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜