2012-11-20 78 views

回答

2

使用View.getLocationOnScreen()和/或getLocationInWindow()。 您可以在onWindowFocusChanged中使用

@Override 
    public void onWindowFocusChanged(boolean hasFocus) { 
     // TODO Auto-generated method stub 
     super.onWindowFocusChanged(hasFocus); 

     int[] locationInWindow = new int[2]; 
     object.getLocationInWindow(locationInWindow); 

     Log.v("TAG","getLocationInWindow() - "+ locationInWindow[0] + " : " + locationInWindow[1]); 
    } 
+0

什麼時候應該調用這些方法?我試圖從onCreate調用它們,但它們返回0( –