搜尋

首頁  >  問答  >  主體

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 天前611

全部回覆(1)我來回復

  • PHP中文网

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

    因為強轉損失了精準度

    回覆
    0
  • 取消回覆