[英]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.