通过监视方向上的以下配置更改AndroidManifest.xml
,例如,假设调用了活动myActivity
,则以下内容就足够了:
<activity android:name=".myActivity"
android:configChanges="orientation"
android:label="MyActivity" />
从myActivity
课堂上,用这个来处理它:
@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
switch(newConfig.orientation){
case Configuration.ORIENTATION_UNDEFINED:
Log.v(TAG, "[onConfigurationChanged] - Undefined");
break;
case Configuration.ORIENTATION_SQUARE:
Log.v(TAG, "[onConfigurationChanged] - Square");
break;
case Configuration.ORIENTATION_PORTRAIT:
Log.v(TAG, "[onConfigurationChanged] - Portrait");
break;
case Configuration.ORIENTATION_LANDSCAPE:
Log.v(TAG, "[onConfigurationChanged] - Landscape");
break;
}
}