Android - Vertical layout only

后端 未结 8 1658
無奈伤痛
無奈伤痛 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:36

    Activity is to block just in case want to block all and only repeat this line of code in their Activitys.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
    
        // Here, talk to the java does not want that the user can rotate their activity.
    
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    or open your "AndroidManisfest.xml" and add the rows for the portrait mode as shown below.

            android:configChanges="orientation"
            android:screenOrientation="portrait">
    

提交回复
热议问题