實習時,看前輩的代碼時看到一個android:screenOrientation
屬性,不太理解,通過度娘瞭解後記錄一下。
android:screenOrientation
屬性可以放在AndroidManifest.xml
的Activity
標籤中用於限制該Activity
啓動時的橫豎屏展示方式,示例:
<activity
android:screenOrientation="landscape"
android:name=".activity.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
這個屬性用於設定該活動的方向,常見的有如下7個可選值
:
- unspecified——默認值,由系統選擇顯示方向,在不同的設備可能會有所不同。
- landscape——橫向
- portrait——縱向
- user——用戶當前的首選方向
- behind——與在活動堆棧下的活動相同方向
- sensor——根據物理方向傳感器確定方向,取決於用戶手持的方向,當用戶轉動設備,他能隨意改變。
- nosensor——不經物理方向傳感器確定方向,該傳感器被忽略,所以當用戶轉動設備,顯示不會跟隨改變,除了這個卻別,系統選擇相同的政策取向對於“未指定”設置,系統根據“未指定”(
unspecified
)設定選擇相同顯示方向。