判断touch点击坐标是否在view中

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

猜你喜欢

转载自blog.csdn.net/android_koukou/article/details/69388187