我一行代码都不懂 |多点触控|


  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)。

基于此链接,其中一个功能是事件自动转发到基础视图。

看起来getXgetY的返回值是相对于某个非原点(例如,捕获事件的对象的左上角)的。

getLocationOnScreen调用用该点填充location,然后您可以使用它从相对坐标生成原始(可能是屏幕)坐标。

最有可能的是,这是因为getTouchedViews需要原始坐标来为您提供此时的视图列表。然后,代码遍历该列表以确定哪个视图应接收事件。

最新更新