【android】禁止横竖屏切换
2015-06-18 16:29
399 查看
今天在一个群里有群友问起、说拍照后返回页面无法显示照片!之前自己的项目也遇到过、只是没有记录,今天在此记录!
在Android 2.3平台上,我们可以需要设置界面的横竖屏显示时,可以在AndroidManifest.xml中,对Activity的属性添加以下代码:
而在3.2之后的平台上则需要多加一个参数 screenSize,写法为:
这是因为在API level 13以后Android做了修改了,SDK描述如下:
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13
or higher (as declared by the minSdkVersion and targetSdkVersion attributes), 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 level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
也就是说在Android 3.2(API level 13)以后,当设备横竖屏切换时屏幕尺寸也改变了。因此,如果你想在API Level 13或者更高的环境下,像以前那样阻止设备的横竖屏切换,你需要在orientation后加上screenSize。也就说你要像这样声明:android:configChanges="orientation|screenSize"。
在Android 2.3平台上,我们可以需要设置界面的横竖屏显示时,可以在AndroidManifest.xml中,对Activity的属性添加以下代码:
android:configChanges="orientation"
而在3.2之后的平台上则需要多加一个参数 screenSize,写法为:
android:configChanges="orientation|screenSize"
这是因为在API level 13以后Android做了修改了,SDK描述如下:
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13
or higher (as declared by the minSdkVersion and targetSdkVersion attributes), 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 level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
也就是说在Android 3.2(API level 13)以后,当设备横竖屏切换时屏幕尺寸也改变了。因此,如果你想在API Level 13或者更高的环境下,像以前那样阻止设备的横竖屏切换,你需要在orientation后加上screenSize。也就说你要像这样声明:android:configChanges="orientation|screenSize"。
相关文章推荐
- android进度条
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)
- 使用traceview进行Android性能测试(转)
- android判断相机图片朝向
- 常用的android弹出对话框
- Android错误提示及解决方案(持续更新)
- Android Camera Api的心得
- Android中的枚举
- Android计算器开发实例
- 【Android】日期拾取器、时间拾取器与菜单
- android sdk离线安装
- Android双击返回键退出程序的实现方法
- Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
- 浅谈JAVA反射机制在Android应用开发中的应用
- android中反射技术使用实例
- Android 打造炫目的圆形菜单 秒秒钟高仿建行圆形菜单
- Android中数据存储--采用SQLite存储数据及在SDCard中创建数据库
- Android应用底部导航栏(选项卡)实例
- 关于使用Android Studio 开发NDK项目生成.h文件方法