判断点击的是否是指定的view

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_41673194/article/details/82912697
    /**
     * 判断点击的是否是指定的view
     * @param view   指定的view
     * @param ev
     * @return
     */
    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/qq_41673194/article/details/82912697
今日推荐