Android 设定横屏,禁止屏幕旋转,Activity重置
2016-05-09 21:04
375 查看
1. 设定屏幕方向
当指定了屏幕的方向后(非 SCREEN_ORIENTATION_UNSPECIFIED ),屏幕就不会自动的旋转了有2中方式控制屏幕方向:
1.1 修改 AndroidManifest.xml
在AndroidManifest.xml的activity中加入:
横屏:
android:screenOrientation=”landscape”
竖屏:
android:screenOrientation=”portrait”
1.2 setRequestedOrientation
横屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
int | SCREEN_ORIENTATION_BEHIND | Constant corresponding to behind in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_FULL_SENSOR | Constant corresponding to fullSensor in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_FULL_USER | Constant corresponding to fullUser in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_LANDSCAPE | Constant corresponding to landscape in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_LOCKED | Constant corresponding to locked in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_NOSENSOR | Constant corresponding to nosensor in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_PORTRAIT | Constant corresponding to portrait in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_REVERSE_LANDSCAPE | Constant corresponding to reverseLandscape in the screenOrientationattribute. |
int | SCREEN_ORIENTATION_REVERSE_PORTRAIT | Constant corresponding to reversePortrait in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_SENSOR | Constant corresponding to sensor in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_SENSOR_LANDSCAPE | Constant corresponding to sensorLandscape in the screenOrientationattribute. |
int | SCREEN_ORIENTATION_SENSOR_PORTRAIT | Constant corresponding to sensorPortrait in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_UNSPECIFIED | Constant corresponding to unspecified in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_USER | Constant corresponding to user in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_USER_LANDSCAPE | Constant corresponding to userLandscape in the screenOrientation attribute. |
int | SCREEN_ORIENTATION_USER_PORTRAIT | Constant corresponding to userPortrait in the screenOrientation attribute. |
2. 禁止屏幕旋转后重置Activity
屏幕旋转后会强制调用 Activity.onCreate 方法,所以会重置Activity禁止方法:
修改 AndroidManifest.xml
android:configChanges=”orientation”
2、设置Activity的android:configChanges="orientation|keyboardHidden|screenSize"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法。
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories