开发者社区> 一叶飘舟> 正文

android 4.0以上版本横竖屏切换后不重建不销毁Activity

简介:
+关注继续查看
在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).

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
android横竖屏切换问题
android横竖屏切换问题
96 0
产品百科 |集成 RTC Android SDK 后如何实现切换横竖屏?
当您成功集成 SDK,并想实现移动端切换横竖屏进行实时音视频通信。您可以阅读本文,了解实现本地切换横竖屏的代码方法,帮助您更好的体验阿里云音视频通信服务。
159 0
Android 横竖屏切换
在配置文件AndroidManifest.xml中配置权限 在配置文件AndroidManifest.xml中的activity接下内配置属性android:configChanges="keyboard|screenSize|orientation|layoutDirection" application接下配置如下: 在相应的Activity中重写onConfigurationChanged方法,在此方法中获取屏幕的信息。
712 0
+关注
文章
问答
文章排行榜
最热
最新
相关电子书
更多
Android组件化实现
立即下载
蚂蚁聚宝Android秒级编译—— Freeline
立即下载
Android开发之多进程架构
立即下载