在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 the minSdkVersion and targetSdkVersionattributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android: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中ActionBar的覆盖叠加
  2. Inflater与findViewById()区别
  3. Android(安卓)View measure(0,0)的作用
  4. Android(安卓)4.4.4 锁屏界面时间大小修改
  5. 定义seekbar样式
  6. 自定义ImageView重写onTouchEvent
  7. Android实现购物车详情简单效果
  8. Test_TextSwitcher 使用方法
  9. Android(安卓)Viewpager中的Fragment 保存状态

随机推荐

  1. Android音频开发(7):音乐可视化-FFT频谱图
  2. Android 动画标签——rotate
  3. android和js的相互调用
  4. Android 多进程之Messenger的使用
  5. Android中的适配器(Adapter)
  6. Android跨进程通信IPC之9——Binder之Fra
  7. Android音频开发(4):PCM转WAV格式音频
  8. android:gravity / android:layout_Gravi
  9. Android音频开发(2):使用AudioRecord录制pcm
  10. 分享10个Android游戏源码,要的赶紧来哈