在AndroidManifest.xml文件的activity节点设置属性 android:configChanges="keyboardHidden|orientation"后可以使应用横竖屏切换时,不会重启对应的 Activity重新加载。可以在对应的Activity java类中重写onConfigurationChanged(Configuration newConfig)方法来处理纵横屏各自的布局,但要记得最后调用super.onConfigurationChanged(newConfig),如果不重写此方法,系统默认使用同一布局。


从3.2版本开始,横竖屏切换时屏幕分辨率可能发生改变,configChanges加入了screenSize属性,例:android:configChanges="orientation|screenSize"

如果仍希望切换后不重建Activity,设定android:targetSdkVersion小于13即可


http://developer.android.com/guide/topics/resources/runtime-changes.html

-------------------------------------------------------------------------------------------------------

Caution: Beginning with Android 3.2 (API level 13), the"screen size" also changes when the device switches between portrait and landscapeorientation. Thus, if you want to prevent runtime restarts due to orientation change when developingfor API level 13 or higher (as declared by theminSdkVersion and targetSdkVersionattributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalareandroid:configChanges="orientation|screenSize". However, if your application targets API level12 or lower, then your activity always handles this configuration change itself (this configurationchange does not restart your activity, even when running on an Android 3.2 or higher device).

更多相关文章

  1. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Fedora镜像
  2. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  3. Android(安卓)Activity界面切换添加动画特效
  4. Android屏幕分辨率正确获取及PX,DPI,DP,SP等的对应关系
  5. IM-A820L限制GSM,WCDMA上网的原理(其他泛泰机型可参考)7.13
  6. Android——开发环境
  7. Android(安卓)Activity界面切换添加动画特效
  8. android调用setRequestedOrientation之后
  9. 实习杂记(27):android中关于横竖屏切换的那些事

随机推荐

  1. win7下mysql6.x出现中文乱码的完美解决方
  2. 详谈mysql order by in 的字符顺序(推荐)
  3. mysql的sql语句特殊处理语句总结(必看)
  4. mysql利用init-connect增加访问审计功能
  5. mysql 5.7.17的最新安装教程图文详解
  6. Mysql inner join on的用法实例(必看)
  7. MySQL 触发器详解及简单实例
  8. mysql服务启动却连接不上的解决方法
  9. mysql取得datetime类型的数据,后面会跟个
  10. InnoDB的关键特性-插入缓存,两次写,自适