[英]Android: Force landscape orientation but allow rotation
我想強制我的Android應用程序進入lanscape方向。 我設法通過在AndroidManifest.xml
添加screenOrientation
來做到這一點,如下所示:
<activity android:name="SomeActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
或者在我唯一的Activity
的onCreate
函數中添加以下行:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
問題是上述兩種解決方案都禁用了旋轉。 如何強制橫向但允許旋轉? 我希望能夠將手機旋轉180度。 從景觀到其他景觀。
您只需將AndroidManifest.xml中的android:screenOrientation
屬性設置為sensorLandscape
請參閱此鏈接http://developer.android.com/reference/android/R.attr.html#screenOrientation
對於您的活動,將屬性設置為sensorLandscape
這使得屏幕可以橫向顯示,但可以使用傳感器來改變屏幕朝向的方向。 對應於SCREEN_ORIENTATION_SENSOR_LANDSCAPE。
代碼示例
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.