问题
I wish to disable the landscape view in an android application . I've used :
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
It works but there is a slightly big problem . If I rotate the screen the activity restarts , and when it comes back , the screen is still in portrait mode . I want my app to completely ignore the device's position . There is no point in disabling the landscape view if when I rotate the device the activity restarts ( the screen becomes black for a few seconds , and then the activity appears again still in portrait mode ) .
回答1:
android:configChanges="orientation|keyboardHidden|keyboard"
回答2:
write a class and extend it to the activity. In that class add this code to a method. setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Then call this method to the activites to which you want to disable the landscape mode..
来源:https://stackoverflow.com/questions/7685163/android-disable-landscape-mode