Ivo Babinec - Leo
Ivo Babinec - Leo

Reputation: 31

Android Orientation Portrait layout only doesnt work

Sorry for this million times repeated answer, (Im a newbe in Andoid), but I cannot achieve to stay layout in Portrait orientation only. I've tried to set it with recommended

android:screenOrientation="portrait"

in Mainfest.xml (for Activity, (have just one)), but it doesn't work. Anyone knows why ?

Below is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.leo.vj">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name_2"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
           android:label="@string/app_name"
           android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>

Upvotes: 2

Views: 1325

Answers (5)

Shiva Snape
Shiva Snape

Reputation: 544

The Problem is there is an extra '>' in end in declaration

    <activity 
             android:name = ".MainActivity">
             android:screenOrientation = "portrait">

Change the Activity Declaration in to :

<activity 
   android:name=".MainActivity"
       android:label="@string/app_name"
       android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <categoryandroid:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

Upvotes: 0

Akshay
Akshay

Reputation: 318

Attribute name mismatch screenOrientation is the correct one

Please see below

android:screenOrientation="portrait"

Upvotes: 0

Kakumanu siva krishna
Kakumanu siva krishna

Reputation: 714

It seems you declared your main activity wrongly.Try this

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name_2"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
   android:label="@string/app_name"
   android:screenOrientation="portrait">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

</activity>
<meta-data
    android:name="preloaded_fonts"
    android:resource="@array/preloaded_fonts" />

Upvotes: 1

Raja Jawahar
Raja Jawahar

Reputation: 6952

The above solution will work. You have missed the config changes.. If you want to acheive through Code.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Upvotes: 0

Mayur Dusane
Mayur Dusane

Reputation: 365

You missed configChanges. In the manifest, set this for all your activities:

<activity android:name=".YourActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>

Upvotes: 1

Related Questions