Android判断一个点是否在矩形区域内

个人遇到的问题判断按钮的点击事件还是滑动事件

   private boolean button1Down = false;
   private boolean button2Down = false;

   private boolean pointInRect(float x, float y, int w, int h) {
            if (x < 0) {  
                return false;
            }
            if (x > w) {
                return false;
            }
            if (y < 0) {
                return false;
            }
            if (y > h) {
                return false;
            }
            return true;
    }

 判断按钮坐标是否在矩形区域内

 tv_button_group.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            button1Down = pointInRect(event.getX(), event.getY(), v.getWidth(), v.getHeight());
                            break;
                        case MotionEvent.ACTION_MOVE:
                            for(int i=0; i
                 //判断向上距离大于300为滑动及隐藏卡片页显示地图页 if (event.getY() < -300) { recyclerView.setVisibility(View.GONE); iv_data.setVisibility(View.GONE); ll_bottom.setVisibility(View.GONE); vw_view.setVisibility(View.GONE); rl_deta.setVisibility(View.GONE); mTitleWidget.setVisibility(View.GONE); im_fanhui.setVisibility(View.VISIBLE); rl_group.setVisibility(View.VISIBLE); itData(mLongitude, mLatitude); uiSettings.setScrollGesturesEnabled(true); //禁止拖拽 isoncl = false; return true; } } break; } return true; } });

 

你可能感兴趣的:(Android判断一个点是否在矩形区域内)