Android中控制屏幕旋轉(zhuǎn)的相關(guān)設(shè)置

轉(zhuǎn)自:http://blog.csdn.net/u012364372/article/details/51088831

設(shè)定屏幕方向
當(dāng)指定了屏幕的方向后,屏幕就不會(huì)自動(dòng)的旋轉(zhuǎn)了

有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. 禁止 屏幕旋轉(zhuǎn)后重置Activity

屏幕旋轉(zhuǎn)后會(huì)強(qiáng)制調(diào)用Activity.onCreate方法,所以會(huì)重置Activity
禁止方法:
修改AndroidManifest.xml

configChanges=”orientation”

最近在做Android的播放器,遇到采用以上方法后,仍然出現(xiàn)屏幕旋轉(zhuǎn)后觸發(fā)Activity.onCreate,經(jīng)查閱資料后,發(fā)現(xiàn)需要添加screenSize處理
具體代碼為:

android:configChanges="orientation|keyboardHidden|screenSize"  
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容