使用onConfigurationChanged活动方法请参阅下列代码:@Overridepublic 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();
}}
您还必须编辑适当的元素在清单文件中包含Android:configChanges只需查看下面的代码:
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
注:对于Android3.2(API级别13)或更高版本,当设备在纵向和横向之间切换时,“屏幕大小”也会发生变化。因此,如果要防止在为api级别13或更高级别开发时由于方向更改而重新启动运行时,则必须声明用于api级别13或更高级别的android:configChanges=“orientation|screenSize”.
希望这能帮到你.。*)