判断touch事件的坐标是否在view中private boolean inRangeOfView(View view, MotionEvent ev) {
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
if (ev.getX() < x || ev.getX() > (x + view.getWidth()) || ev.getY() < y || ev.getY() > (y + view.getHeight())) {
return false;
}
return true;
}
本文介绍了一个用于判断触摸事件坐标是否位于指定视图内的方法。通过获取视图在屏幕上的位置和尺寸,可以有效地确定触控操作是否针对该视图。

被折叠的 条评论
为什么被折叠?



