在实现一个view移动的时候,用getX移动时,会造成view的跳动,用getRawX则没有这个问题,主要代码如下:
int lastX;
int lastY;
@Override
public boolean onTouchEvent(MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
// int x = (int)event.getRawX();
// int y = (int)event.getRawY();
//
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
lastX = x;
lastY = y;
break;
case MotionEvent.ACTION_MOVE:
int distanceX = x - lastX;
int distanceY = y - lastY;
layout(getLeft()+distanceX,getTop()+distanceY,getRight()+distanceX,getBottom()+distanceY);
lastX = x;
lastY = y;
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
谁能帮忙解答一下?