On the emulator Android 2.1.
In the test class ActivityInstrumentationtestCase2,
I claim that phototButton is above 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] }
I expected different values from these methods.
Why do getLocationOnScreen () and getLocationInWindow () return the same value?
source share