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);


ActivityInfo:

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




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

屏幕旋转后会强制调用Activity.onCreate方法,所以会重置Activity

禁止方法:

修改AndroidManifest.xml

android:configChanges=”orientation”


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

具体代码为:

android:configChanges="orientation|keyboardHidden|screenSize"


禁止重置Activity会造成Screen的宽高颠倒, 需要手动修正。





更多相关文章

  1. android keytool 不是内部命令或外部命令在 (win7下不能用的解决
  2. Arcgis android 10.2安装方法
  3. Android studio 打不开官方虚拟机 100%成功解决方法
  4. 输入法软键盘搜索执行两次的解决方法
  5. Android 开发——'Android Pre Compiler'空指针问题的解决方法
  6. 【 Android】使手机屏幕常亮,不进入待机状态
  7. Android中屏幕相关的操作
  8. android TextView的字体颜色设置的多种方法(续)
  9. Android 仿微信TabHost使用方法详解

随机推荐

  1. Android文件系统的结构及目录用途、操作
  2. Android开发者指南(7) ―― App Install
  3. android 桌面小部件(App Widgets)如何显示
  4. Android(安卓)MaterialButton的一些问题
  5. Android的各种基本应用
  6. Android Canvas 切割 clipRect
  7. 赵雅智_ListView
  8. TextView跑马灯无效的解决办法
  9. EditText 修改光标颜色及位置
  10. Android ADT 找不到Annotation Processin