转自:http://blog.csdn.net/u012364372/article/details/51088831

设定屏幕方向
当指定了屏幕的方向后,屏幕就不会自动的旋转了

有2种方式控制屏幕方向:

修改AndroidManifest.xml

1 在AndroidManifest.xml的activity中加入:
横屏:
android:screenOrientation=”landscape”
竖屏:
android:screenOrientation=”portrait”

2 setRequestedOrientation
横屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

ActivityInfo:

int SCREEN_ORIENTATION_BEHIND Constant corresponding to behind in the screenOrientation attribute.

intSCREEN_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 screenOrientation attribute.

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 screenOrientation attribute.

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.

  1. 禁止 屏幕旋转后重置Activity

屏幕旋转后会强制调用Activity.onCreate方法,所以会重置Activity
禁止方法:
修改AndroidManifest.xml

configChanges=”orientation”

最近在做Android的播放器,遇到采用以上方法后,仍然出现屏幕旋转后触发Activity.onCreate,经查阅资料后,发现需要添加screenSize处理
具体代码为:

android:configChanges="orientation|keyboardHidden|screenSize"  

更多相关文章

  1. android中获取屏幕相关信息
  2. activity 设置Theme.Dialog View高度
  3. Android实现网络加载图片点击大图后浏览可缩放
  4. Unity 实现Android不锁屏
  5. android 获得屏幕、视图、任务栏、状态栏的高宽以及屏幕的设置
  6. android中手势操作图片的平移、缩放、旋转
  7. 我的Android进阶之旅------>Android常用计量单位(Dimension)的介绍
  8. 安卓设备修改屏幕像素密度以及查看屏幕分辨率
  9. Google Analytics Advanced Configuration - Google Analytics

随机推荐

  1. Android安全知识库
  2. android phone电话调用流程(转贴)
  3. android 开发 时间的计算问题
  4. Android(安卓)Studio——Message
  5. 【Android】win10操作系统下Android开发
  6. Android(安卓)Studio开发常见问题及解决
  7. Android App 结束运行后重启
  8. Androidx和Android(安卓)support库的冲突
  9. Android(安卓)可任意拖动的悬浮窗(类似悬
  10. 【Java】java和android网络编程 - 对byte