问题
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?
回答1:
In your manifest file, add this to your activity which you don't want to rotate:
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
This will prevent it from ever rotating, including if the phone has a slide out keyboard.
I hope this helps.
回答2:
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:
android:screenOrientation="portrait">
来源:https://stackoverflow.com/questions/5815865/android-handle-orientation-change-w-o-rotating-screen