在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 changeswhen 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 theminSdkVersionandtargetSdkVersionattributes), 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. 【Android(安卓)界面效果6】Android(安卓)控件之ImageSwitcher图
  2. 自定义 Android(安卓)Preference——SpinnerPreference的私人定
  3. Android手机横竖屏幕切换时Activity的重启问题
  4. Android(安卓)使用level-list改变对应的状态图片
  5. Android之back键拦截处理
  6. Android系列之利用SharedPreferences是否是第一次进入安装程序
  7. Ant 打包 Android(安卓)Project
  8. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Fedora镜像
  9. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像

随机推荐

  1. Android(安卓)Intent传递对象小结
  2. android 自定义进度条下载apk并更新
  3. android handler和looper
  4. Android之WebView与原生js之间的相互调用
  5. Android控件开发之CheckBox
  6. Android和.NET通用的AES算法 好东东 收
  7. 学习笔记-androidmanifest说明
  8. Android(安卓)webView 软键盘覆盖输入框,w
  9. Android(安卓)实现生成二维码
  10. Android(安卓)获取经纬度同时获取当前具