В эмуляторе Android 2.1.
В тестовом классе ActivityInstrumentationtestCase2
Я утверждаю, что phototButton выше sendButton.
@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 () возвращают одинаковые значения?