MotionEvent中getX()和getRawX()的区别

先看一段代码:

public class Res extends Activity implements View.OnTouchListener {

	Button btn = null;
	int x = 0;
	int y = 0;
	int rawx = 0;
	int rawy = 0;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		btn = (Button) findViewById(R.id.button);
		btn.setOnTouchListener(this);
	}

	public boolean onTouch(View view, MotionEvent event) {
		int eventaction = event.getAction();
		switch (eventaction) {
		case MotionEvent.ACTION_DOWN:
			break;
		case MotionEvent.ACTION_MOVE:
			x = (int) event.getX();
			y = (int) event.getY();
			rawx = (int) event.getRawX();
			rawy = (int) event.getRawY();
			Log.d("DEBUG", "getX=" + x + "getY=" + y + "\n" + "getRawX=" + rawx
					+ "getRawY=" + rawy + "\n");
			break;

		case MotionEvent.ACTION_UP:

			break;
		}
		return false;
	}
}

 

 

再看一张图片说明:

 

C点表示手指触摸点

 

C点表示手指触摸点

你可能感兴趣的:(event)