android - 为什么onTouch事件的event.getRawX() 等参数使用强转到int反而更准确了
ringa_lee
ringa_lee 2017-04-17 17:55:21
0
1
607

为什么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_lee
ringa_lee

ringa_lee

全部回复(1)
洪涛

因为强转损失了精度

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板