Android 手柄方向更改,无需旋转屏幕
如何在不旋转屏幕的情况下处理屏幕方向?
我在活动中覆盖了 onConfigurationChanged
,并尝试注释掉调用 super.onConfigurationChanged
和我的应用程序强制关闭。我尝试的下一步是在调用 super.onConfigurationChanged
之前将此方法的 newConfig 参数中的方向属性设置为 newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
。但我的屏幕仍然旋转了。
我的最后一个实现是处理传感器(陀螺仪)运动。但还有其他方法可以做到这一点吗?
还有其他想法吗?
How to handle screen orientation without rotating screen?
I have override onConfigurationChanged
in my activity and try to comment out call super.onConfigurationChanged
and my application Force Closes. Next thing I've tried was to set orientation attribute in newConfig parameter of this method to newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
before call super.onConfigurationChanged
. But still my screen has rotated.
My last implementation would be to handle sensor (gyroscope) movement. But is there any other way to do this?
Any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在清单文件中,将其添加到您不想旋转的活动中:
这将阻止其旋转,包括手机具有滑出式键盘的情况。
我希望这有帮助。
In your manifest file, add this to your activity which you don't want to rotate:
This will prevent it from ever rotating, including if the phone has a slide out keyboard.
I hope this helps.
如果您希望将活动限制为仅一种方向,请将以下内容添加到清单文件中的每个活动中:
If you're looking to restrict your activities to only one kind of orientation, then add the following to each of the activites in your manifest file: