android 判断点击的位置是不是在指定的view上

2025-04-16 00:31:45
推荐回答(1个)
回答(1):

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; }