android关于横竖屏切换

来源:互联网 发布:制作手持身份证软件 编辑:程序博客网 时间:2024/05/16 12:29

注:如果项目不需要屏幕切换时可以设置为

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);    }


0 0