Android 2.1 에뮬레이터를 사용 중입니다.
ActivityInstrumentationtestCase2 테스트 클래스에서
저는 phototButton이 sendButton 위에 있다고 주장합니다.getLocationOnScreen() 및 getLocationInWindow()가 같은 값을 반환하는 이유는 무엇입니까?
@UiThreadTest public void testViewLocationOnScreen() {
// Trying to trigger layout
activity.findViewById(R.id.rootSnap).forceLayout();
activity.findViewById(R.id.rootSnap).requestLayout();
activity.photoButton.getRootView().requestLayout();
activity.photoButton.requestLayout();
activity.photoButton.invalidate();
activity.onWindowFocusChanged(true);
// Successfull asserts
assertTrue(activity.hasWindowFocus());
ViewAsserts.assertOnScreen(activity.photoButton.getRootView(), activity.photoButton);
ViewAsserts.assertOnScreen(activity.sendButton.getRootView(), activity.sendButton);
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Assert.assertTrue(activity.photoButton.isShown());
Assert.assertTrue(activity.sendButton.isShown());
// Unexpected screen coordinates returned from
// getLocationOnScreen() and getLocationInWindow()
int[] above = new int[2];
activity.photoButton.getLocationOnScreen(above);
int[] below = new int[2];
activity.sendButton.getLocationOnScreen(below);
log("getLocationOnScreen-above", above);
log("getLocationOnScreen-below", below);
// Logs screen coodinates [0, 76] and [0, 178]
above = new int[2];
activity.photoButton.getLocationInWindow(above);
below = new int[2];
activity.sendButton.getLocationInWindow(below);
log("getLocationInWindow-above", above);
log("getLocationInWindow-below", below);
// Logs window coordinates [0, 76] and [0, 178]
}
나는이 방법들과 다른 값을 기대하고있었습니다.
getLocationOnScreen() 및 getLocationInWindow()가 같은 값을 반환하는 이유는 무엇입니까?
[이 질문] (http://stackoverflow.com/questions/2638342/incorrect-coordinates-from-getlocationonscreen-getlocationinwindow)을 보셨습니까? – Knickedi
Re-phrase :이 메서드가 동일한 값을 반환하는 것이 정상입니까/보통입니까? Window 및 Screen의 의미를 잘못 해석합니까? 나는 항상 다른 값을 반환해야 함을 이해합니다. – user77115