getX 和getRawX

虽然知道getX是返回相对控件的坐标,getRawX返回的相对屏幕的坐标,但是脑子一下子转不过来,
认为在移动控件的时候,使用getX 相减获得偏移量和getRawX的应该是一样的。
实际跑一下发现会有鬼畜效果,后来想了一下getX在获得坐标的时候 控件移动了,就会导致获得的坐标偏移量“不准确”。

简直太白痴了。。


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = event.getX();
                lastY = event.getY();
                lastRawX = event.getRawX();
                lastRawY = event.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                float disX = event.getX() - lastX;
                float disY = event.getY() - lastY;


                float disRawX = event.getRawX() - lastRawX;
                float disRawY = event.getRawY() - lastRawY;
                PtrCLog.d("JellyTextView", "disX    ====: " + disX);
                PtrCLog.d("JellyTextView", "lastX   ====: " + lastX);
                PtrCLog.d("JellyTextView", "disRawX ====: " + disRawX);
                PtrCLog.d("JellyTextView", "lastRawX====: " + lastRawX);

                PtrCLog.d("JellyTextView", "====");

                offsetLeftAndRight((int) disRawX);
                offsetTopAndBottom((int) disRawY);
                lastX = event.getX();
                lastY = event.getY();

                lastRawX = event.getRawX();
                lastRawY = event.getRawY();
                break;
            case MotionEvent.ACTION_UP:
                mScroller.startScroll((int) getX(), (int) getY(), -(int) (getX() - startX),
                        -(int) (getY() - startY));
                invalidate();
                break;
        }
        /**
         public final float getRawX () {
         return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
         }

         public final float getX(int pointerIndex) {
         return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
         }
         */
        return super.onTouchEvent(event);
    }

你可能感兴趣的:(getX 和getRawX)