Programmatically lock into portrait mode for certain operations

后端 未结 2 386
感情败类
感情败类 2020-12-01 05:21

Is there a way to programmatically lock an app in portrait mode for certain operations, and then resume (and have the app rotate to landscape if the user is holding the devi

相关标签:
2条回答
  • 2020-12-01 05:33

    I'm reading into your question a bit, but if the problem you are facing is that the reload of the activity causes problems, you can add in the manifest a line to handle the orientation changes yourself. You'll probably need to do this anyway if you want to do something special for the orientation changes, but perhaps just adding the lines will take care of your problems for you:

    <activity android:name=".MyActivity"  
        android:configChanges="keyboard|keyboardHidden|orientation" />
    
    0 讨论(0)
  • 2020-12-01 05:41

    Try this:

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    //Do your operation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    
    0 讨论(0)
提交回复
热议问题