开发者

detect where on the screen onTouchevent happened

I've got an onTouchEvent boolean on a Surfaceview, I've got openGL objects drawn on the view and I'm wondering is there anyway to detect where on the screen the onTouch happen开发者_运维知识库ed? e.g (x,y) co-ordinates.


Use event.getX() and event.getY() assuming that you have the following method signature:

  public boolean onTouch(View view, MotionEvent event)


when you touch the screen, you will get the that position x,y position range. @Override public boolean onTouchEvent(MotionEvent ev) {

    // Normal touch
                                    xPosition = ev.getX();
                yPosition = ev.getY();
        switch (ev.getAction()) {

        case MotionEvent.ACTION_DOWN:
                            {
                dx = ev.getX();
                dy = ev.getY();

                } 
        return ;
          }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜