点击区域,是否在某个view内
2022-06-16 本文已影响0人
皓皓amous
private boolean isWithinViewRange(View view, int x, int y) {
if (null == isWithinViewRangerRect) {
isWithinViewRangerRect = new Rect();
}
view.getDrawingRect(isWithinViewRangerRect);
int[] location = new int[2];
view.getLocationOnScreen(location);
isWithinViewRangerRect.left = location[0];
isWithinViewRangerRect.top = location[1];
isWithinViewRangerRect.bottom = isWithinViewRangerRect.bottom + location[1];
isWithinViewRangerRect.right = isWithinViewRangerRect.right + location[0];
return isWithinViewRangerRect.contains(x, y);
}