0
我使用此代碼來檢測佈局方向更改,但下面的代碼使用相同的肖像佈局,而不是保存在layout-land中的佈局。Android的方向更改
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
[Android Orientation Change]的可能重複(http://stackoverflow.com/questions/4616176/android-orientation-change) – 2012-03-12 05:53:41
你是什麼意思?當你改變方向時,它是否總是落在「else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){」case並顯示「portrait」?或者佈局沒有變化? – AndroDev 2012-03-13 11:55:11