我怎么知道,如果一个MotionEvent是相对的还是绝对的?

人气:1,041 发布:2022-09-10 标签: android touch

问题描述

我在执行 OnTouchListener 和我收到MotionEvent对象。有些 ACTION_MOVE 事件报告绝对X / Y坐标,而有些报告的相对坐标。

I am implementing OnTouchListener and am receiving MotionEvent objects. Some ACTION_MOVE events reports absolute X/Y coordinates, while some reports relative coordinates.

我怎么能问一个 MotionEvent 什么样的​​坐标是目前重新presents?

How can I ask a MotionEvent what kind of coordinates it currently represents?

推荐答案

您可能需要使用这些绝对坐标(绝对的,对于设备的屏幕):

You may want to use these for absolute coordinates (absolute, regarding the screen of the device):

MotionEvent.getRawX()

MotionEvent.getRawY()

其他方法,的getX() getY()以,应该返回你的坐标,​​相对于查看,分派他们。

The other methods, getX() and getY(), should return you coordinates, relative to the View, that dispatched them.

783