private void dealEvent(int actionPointerIndex, MotioEvent event,
View eventView, int actionresolved) {
int rawX, rawY;
int location[] = { 0, 0 };
eventView.getLocationOnScreen(location);
rawX = (int) event.getX(actionIndex) + location[0];
rawY = (int) event.getY(actionIndex) + location[1];
ArrayList<View> views = getTouchedViews(rawX, rawY, actionresolved);
我不明白这句话,我们为什么要这样做?
rawX = (int) event.getX(actionIndex) + location[0];
rawY = (int) event.getY(actionIndex) + location[1];
ArrayList<View> views = getTouchedViews(rawX, rawY, actionresolved);
这
主要是假设,因为您提供的代码不太可编译(MotioEvent
应该MotionEvent
并且您在函数声明中使用actionPointerIndex
,在正文中使用actionIndex
)。
基于此链接,其中一个功能是事件自动转发到基础视图。
看起来getX
和getY
的返回值是相对于某个非原点(例如,捕获事件的对象的左上角)的。
getLocationOnScreen
调用用该点填充location
,然后您可以使用它从相对坐标生成原始(可能是屏幕)坐标。
最有可能的是,这是因为getTouchedViews
需要原始坐标来为您提供此时的视图列表。然后,代码遍历该列表以确定哪个视图应接收事件。