现在的位置: 首页 > 综合 > 正文

判断touch事件点是否在view范围内

2018年02月10日 ⁄ 综合 ⁄ 共 655字 ⁄ 字号 评论关闭

    private Rect mChangeImageBackgroundRect = null;

    private boolean isInChangeImageZone(View view, int x, int y) {

        if (null == mChangeImageBackgroundRect) {
            mChangeImageBackgroundRect = new Rect();
        }
        view.getDrawingRect(mChangeImageBackgroundRect);

        int[] location = new int[2];
        view.getLocationOnScreen(location);

        mChangeImageBackgroundRect.left = location[0];
        mChangeImageBackgroundRect.top = location[1];
        mChangeImageBackgroundRect.right = mChangeImageBackgroundRect.right + location[0];
        mChangeImageBackgroundRect.bottom = mChangeImageBackgroundRect.bottom + location[1];

        return mChangeImageBackgroundRect.contains(x, y);

    }

其中view是要判断的view ,x,y是Down X, Down Y

抱歉!评论已关闭.