4
在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
重新短語:這些方法返回相同的值是否正常/正常? 我誤解了窗口和屏幕的含義嗎?根據我的理解,它們應該總是返回不同的值。 – user77115