2015-11-01 69 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); 
    }