0
後,我用這個方法,當我旋轉屏幕之前加載狀態:獲取圖像的座標旋轉
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
view1 = new DrawView(this);
setContentView(view1);
Bundle bundle = this.getIntent().getExtras();
onRestoreInstanceState(bundle);
getCoordinates();//NO WORKS WELL
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
//Here I set the values to images: colors, borders, etc ...
}
而且我在AndroidManifest下一行:
android:configChanges="orientation|screenSize"
在getCoordinates()方法我有下一個代碼:
public void getCoordinates(){
final int[] values = new int[2];
image.getLocationInWindow(values);
x = values[0];
y = values[1];
width = image.getWidth();
height = image.getHeight();
}
前面的代碼並不完全是我h但它只是一個例子。我的真實代碼沒有太大變化。 但我有一個問題,我必須知道圖像的座標以在圖像之間繪製線條。但是,如果我通過示例(onConfigurationChanged(Configuration newConfig))啓動該方法,由於該方法尚未執行所有行,且該方法尚未結束,則UI未完全加載。因此在座標中得到空值。 我不知道如何在用戶界面完全充電以獲得座標時自動啓動getCoordinates()方法。任何人都可以幫助我?
謝謝!!!!