Android - Vertical layout only

后端 未结 8 1648
無奈伤痛
無奈伤痛 2021-01-31 07:26

How do I make sure my app is only for vertical layout?

I have tried android:screenOrientation=\"portrait\" but that doesn\'t seem to do the trick.

8条回答
  •  清酒与你
    2021-01-31 07:47

    If you want some group of your activities to be locked on PORTRAIT mode only, than you can choose the next way:

    public abstract class BasePortraitActivity extends Activity {
    
        @Override
        protected final void onCreate(Bundle state) {
            super.onCreate(state);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            performOnCreate(state);
        }
    
        protected abstract void performOnCreate(Bundle state);
    
    }
    

    And than just extend BasePortraitActivity where you need it. Or just add setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to YourActivity.onCreate().

提交回复
热议问题