在纵向或纵向反转活动只纵向

2023-09-04 08:32:06 作者:明知是梦,心却在痛

我希望我的活动,只在纵向模式下可用 - 纵向和reversePortrait。我怎样才能做到这一点?当我设置安卓screenOrientation =画像这将迫使活动只有在正常的肖像 - 反之亦然reversePortrait。

请不要告诉我,这是一个不错的办法,迫使/锁方向。我知道这件事情,但还是客户端请求的。感谢您的理解和任何想法。

更新: API级别11和更高

解决方案

如果您在API层面9+,使用安卓screenOrientation =sensorPortrait   

肖像取向的,但可以是正常或反向肖像   基于设备传感器。新增的API级别9。

Documentation

行业动态 还要跌 一线生猪产能淘汰白热化 下半年周期反转存分歧

I want my activity to be available only in both portrait modes - portrait and reversePortrait. How can I achieve this? When I set android:screenOrientation="portrait" it will force activity to be only in normal portrait - vice versa with reversePortrait.

Please, don't tell me it's a bad approach to force/lock orientation. I know about it, but still client is requesting it. Thanks for understanding and for any ideas.

UPDATE: API Level 11 and higher

解决方案

If you are on API level 9+, use android:screenOrientation="sensorPortrait".

Portrait orientation, but can be either normal or reverse portrait based on the device sensor. Added in API level 9.

Documentation