2015-11-01 68 views

回答

4

你必须做这样的事情。在Activity你必须覆盖

dispatchTouchEvent 

所以在你的onCreate找到你的看法

RelativeLayout yourLayout = (RelativeLayout) findViewById(R.id.yourLayout); 

然后

@Override 
public boolean dispatchTouchEvent(MotionEvent ev) { 

     float touchPointX = ev.getX(); 
     float touchPointY = ev.getY(); 
     int[] coordinates = new int[2]; 
     yourLayout.getLocationOnScreen(coordinates); 
     if (touchPointX < coordinates[0] || touchPointX > coordinates[0] + yourLayout.getWidth() || touchPointY < coordinates[1] || touchPointY > coordinates[1] + yourLayout.getHeight()){ 
      //Do Your ACTION 
    } 
    return super.dispatchTouchEvent(ev); 
    }