注:如果项目不需要屏幕切换时可以设置为
1. android:screenOrientation="portrait" 始终以竖屏显示
2. android:screenOrientation="landscape" 始终以横屏显示
屏幕切换时生命周期为
onPause
onStop
onDestroy
onCreate
onStart
onResume
Activity会先销毁然后重新加载。
可以修改android:configChanges属性使当前Activity不销毁。
在4.0 以后需要加上screenSize这个属性,也就是
android:configChanges="keyboardHidden|orientation|screenSize"
或者
android:configChanges="orientation|screenSize"
都可以。
监听系统设置的更改
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
String message = newConfig.orientation == newConfig.ORIENTATION_LANDSCAPE?"横屏":"竖屏";
Log.e(tag, message);
}
本文详细介绍了在Android应用中如何设置屏幕方向,包括竖屏和横屏显示方式,以及如何在屏幕方向改变时进行事件监听,确保应用在不同设备上的良好用户体验。
2190

被折叠的 条评论
为什么被折叠?



