方法一:
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- if (!(event.getX() >= -10 && event.getY() >= -10)
- || event.getX() >= calendarLayout.getWidth() + 10
- || event.getY() >= calendarLayout.getHeight() + 20) {//如果点击位置在当前View外部则销毁当前视图,其中10与20为微调距离
- finish();
- }
- }
- return true;
- }
方法二:
调用
- setCanceledOnTouchOutside(true);