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);
I don’t understand these line, why do we do that?
rawX = (int) event.getX(actionIndex) + location[0];
rawY = (int) event.getY(actionIndex) + location[1];
ArrayList<View> views = getTouchedViews(rawX, rawY, actionresolved);
This is mostly supposition since the code you provided isn’t quite compilable (
MotioEventshould beMotionEventand you useactionPointerIndexin the function declaration andactionIndexin the body).Based on this link, one of the features is that the events are automatically forwarded to the underlying view.
It looks like the return values from
getXandgetYare relative to some non-origin point (for example, the upper left corner of the object which captured the event).The
getLocationOnScreencall populateslocationwith that point and you then use that to generate raw (probably screen) co-ordinates from the relative ones.Most likely, that’s because
getTouchedViewsrequires raw co-ordinates to give you a list of views at that point. The code then goes through that list to figure out which view should receive the event.