How to fix layout orientation to vertical?

前端 未结 7 1493
自闭症患者
自闭症患者 2021-01-31 06:51

How to fix layout orientation to portrait and do not allow changing from portrait to landscape during run time?

7条回答
  •  时光说笑
    2021-01-31 07:24

    Use setRequestedOrientation() as shown:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

提交回复
热议问题