2011-04-18 93 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); 
    } 
} 
相关问题