How to fix layout orientation to vertical?

前端 未结 7 1483
自闭症患者
自闭症患者 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);
    
    0 讨论(0)
  • 2021-01-31 07:24

    In your AndroidMainfest.xml just write this in your activity you declare,

    If you want in layout vertical than use

    android:screenOrientation="portrait"
    

    If you want in layout landscape than use

    android:screenOrientation="landscape"
    
    0 讨论(0)
  • 2021-01-31 07:33

    If you want to freeze orientation at runtime, then you you can implement this:

    Android: Temporarily disable orientation changes in an Activity

    I use a similar approach and it works perfectly.

    0 讨论(0)
  • 2021-01-31 07:33
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    before

    setContentView(R.layout.main);
    
    0 讨论(0)
  • 2021-01-31 07:38

    In your AndroidMainfest.xml file find the tags of the activities you wish to lock to a given rotation, and add this attribute:

    android:screenOrientation="portrait"
    
    0 讨论(0)
  • 2021-01-31 07:38

    in your activity parameters in Manifest File

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.statepermit" android:versionCode="1" android:versionName="1.0">
        <application android:icon="@drawable/stateheader" android:label="@string/app_name">
            <activity android:name=".statepermit" android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
        <uses-sdk android:minSdkVersion="7" />
    
    </manifest>
    

    android:screenOrientation="portrait"

    0 讨论(0)
提交回复
热议问题