標籤:line hit androi tab tar 12px 橫屏 snippet track
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的寬高顛倒, 須要手動修正。
Android 設定橫屏,禁止旋轉螢幕,Activity重設 [更新視頻播放器相關]