search

Home  >  Q&A  >  body text

android - 为什么onTouch事件的event.getRawX() 等参数使用强转到int反而更准确了

为什么onTouch事件的event.getRawX() 等参数使用强转到int反而更准确了

       mImageView.setOnTouchListener(new View.OnTouchListener() {

            private int mStartX;
            private int mStartY;
 @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mStartX = (int) event.getRawX();
                        mStartY = (int) event.getRawY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        int newX = (int) event.getRawX();
                        int newY = (int) event.getRawY();
                        int moveX = newX - mStartX;
                        int moveY = newY - mStartY;
                        mParams.x += moveX;
                        mParams.y += moveY;
                        mStartX = (int) event.getRawX();
                        mStartY = (int) event.getRawY();
                        mWindowManager.updateViewLayout(mImageView,mParams);
                        break;
                    case MotionEvent.ACTION_UP:
                        Toast.makeText(RocketService.this, "asdgasds", Toast.LENGTH_SHORT).show();
                        break;
                }
                return true;
            }
ringa_leeringa_lee2773 days ago612

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:57:21

    Accuracy is lost due to forced transfer

    reply
    0
  • Cancelreply