点击区域,是否在某个view内

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

你可能感兴趣的:(点击区域,是否在某个view内)