Android:在 setRequestedOrientation 后自动旋转不起作用 [英] Android: Auto Rotate not working after setRequestedOrientation
问题描述
我有一个视频播放器,其中有两个功能:
I have a video player in which I have two features:
如果自动旋转被禁用,并且当用户点击全屏按钮时,我会使用
setRequestedOrientation() 强制
并在退出全屏时返回纵向视图.orientation
进入landscape
视图ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
If the auto-rotate is disabled and when the user clicks on fullscreen button I force the
orientation
to go inlandscape
view usingsetRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
and back to portrait view when fullscreen is exited.
我已覆盖 onConfigurationChanged
以检测用户启用自动旋转功能时方向的变化,并根据方向更改活动视图.
I have overridden the onConfigurationChanged
to detect the change in orientation when the auto-rotate feature is enabled by user and change the activity view according to the orientation.
现在这个设置的问题是,如果用户启动活动并进入全屏,并且 setRequestedOrientation
被调用一次,稍后当 auto-rotate
启用时,活动不会收到方向更改并且 onConfigurationChanged
不会被调用.
Now the problem with this setup is that if user start the activity and goes in fullscreen and setRequestedOrientation
get invoked once, later when auto-rotate
is enabled, the activity doesn't receive the orientation changes and the onConfigurationChanged
doesn't get called.
我在这里读到(https://stackoverflow.com/a/6109206/5167868)他们不会同时工作.
I read here (https://stackoverflow.com/a/6109206/5167868) that they wont work simultaneously.
我想知道是否有办法实现这两者,因为我看到像 MX Player
这样的播放器在他们的应用中执行此操作.
I would like to know if there a way of implementing both as I have seen players like MX Player
do this in their app.
推荐答案
使用 setRequestedOrientation()
固定屏幕方向后,自动旋转功能将不起作用.所以为了让它工作,你可以做这样的事情:
After you fix the orientation of the screen by using setRequestedOrientation()
, Auto Rotate feature won't work. So to make it work, you may do something like this:
使用以下方法设置方向后:setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
After you set your orientation using: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
这样称呼:setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
这将使自动旋转再次工作!
This shall make the auto rotate to work again!
这篇关于Android:在 setRequestedOrientation 后自动旋转不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!