Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix layout orientation to vertical?

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

like image 858
Harinder Avatar asked Apr 18 '11 11:04

Harinder


People also ask

How do I change my page from horizontal to vertical?

Use different orientations in the same document Select the pages or paragraphs whose orientation you want to change. Click PAGE LAYOUT > Page Setup dialog box launcher. In the Page Setup box, under Orientation, click Portrait or Landscape. Click the Apply to box, and click Selected text.

How do I fix landscape to portrait?

Choose either landscape (horizontal) or portrait (vertical) orientation for all, or part, of your document. Click PAGE LAYOUT > Orientation. Click Portrait, or Landscape.

How do I fix the orientation on my Android phone?

To do this, swipe down from the right side of the top panel. Hold the device in the orientation in which you want it locked. On the drop-down menu, touch the “Auto Rotate” button. The “Auto Rotate” button becomes the “Rotation Locked” button.


4 Answers

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"
like image 82
Jim Blackler Avatar answered Oct 09 '22 14:10

Jim Blackler


Use setRequestedOrientation() as shown:

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

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
like image 30
David Choe Avatar answered Oct 09 '22 16:10

David Choe


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"

like image 16
Hardik Gajjar Avatar answered Oct 09 '22 16:10

Hardik Gajjar


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.

like image 3
user695977 Avatar answered Oct 09 '22 14:10

user695977