Android handle orientation change w/o rotating screen

会有一股神秘感。 提交于 2019-12-08 04:04:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!