Place image at coordinates Android

后端 未结 3 1648
一整个雨季
一整个雨季 2020-12-15 12:34

I have a program in which I would like to place an image at the coordinates of a touch event. I have the coordinates now I just need help with placing an image there. I will

3条回答
  •  -上瘾入骨i
    2020-12-15 13:24

    To place a image at a certain coordinates you will have to draw the image on the canvas . To get the coordinates of the touch event use the following code:

    @Override
    public void onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            mTouchX = event.getX();
            mTouchY = event.getY();//stores touch event
        } else {
            mTouchX = -1;
            mTouchY = -1;
        }
        super.onTouchEvent(event);
    }
    

提交回复
热议问题