Android处理方向的改变W / O旋转屏方向、Android

2023-09-06 19:18:27 作者:浅蓝色初夏

如何处理屏幕方向没有旋转屏?

How to handle screen orientation without rotating screen?

我必须重写 onConfigurationChanged 在我的活动,并尝试注释掉调用 super.onConfigurationChanged 和我的应用程序强制关闭。我试着下一件事情就是在这个方法的参数NEWCONFIG方向属性设置为 newConfig.orientation = Configuration.ORIENTATION_PORTRAIT;呼叫之前 super.onConfigurationChanged 。但是还是我的屏幕旋转了。

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?

任何其他的想法?

推荐答案

在您的清单文件,将它添加到你的活动,你不想旋转:

In your manifest file, add this to your activity which you don't want to rotate:

android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"

从不断旋转的,包括如果手机有键盘进行幻灯片这将prevent它。

This will prevent it from ever rotating, including if the phone has a slide out keyboard.

我希望这有助于。