手指在ImageView上拖动

时间:2016-12-27 14:32:55

标签: android

我试图在ImageView上移动手指时知道手指的位置 但我每次触摸都会上下起伏。

    myIM = (ImageView)findViewById(R.id.imageView);
    myIM.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            switch (motionEvent.getAction())
            {
                case MotionEvent.ACTION_MOVE:
                {
                    int x = (int) motionEvent.getRawX();
                    int y = (int) motionEvent.getRawY();
                    Log.d("DTAG","Move");
                    Log.d("DTAG","x: "+x);
                    Log.d("DTAG","y: "+y);
                }
                case MotionEvent.ACTION_DOWN:
                {
                    Log.d("DTAG","Down");
                }
                case MotionEvent.ACTION_UP:
                {
                    Log.d("DTAG","UP");
                }

            }
            return false;
        }
    });

日志:

D/DTAG: Down
D/DTAG: UP
D/DTAG: Down
D/DTAG: UP

0 个答案:

没有答案