2011-04-18 98 views

回答

2

其實,在清單的Activity聲明

  android:configChanges="orientation" 
      android:screenOrientation="landscape" 

屬性並不妨礙活動被重建時方向的變化,它可以防止平臺從做任何方向默認並保持默認,例如景觀。

您可以覆蓋

public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
    setContentView(R.layout.newLayout); 
} 

給力活動的娛樂。

1

如果您有2種佈局(縱向和橫向)並且平板電腦上的訂單似乎相反,則切換到使用getRotation而不是棄用的getOrientation。像這樣的東西

private void setLayout() { 
    // Get display for detecting the phone orientation 
    final Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); 
    if (display.getRotation() == Surface.ROTATION_0 || display.getRotation() == Surface.ROTATION_180) { 
     setContentView(R.layout.home); 
    } else { 
     setContentView(R.layout.home_l); 
    } 
} 
相關問題