sealz sealz - 1 month ago 11
Android Question

Android App to always stay in Landscape

I have looked Here but am still unable to tackle my problem.

I have recently jumped into android (headfirst) and have been messing around. I would like my application to only run in Landscape mode no matter which way the screen is tilted.

My home screen is basically a page with a background and a few buttons that are aligned on the right side.

Here is my XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft = "450px"
android:paddingRight = "60px"
android:paddingTop="25px"
//I have tried adding orientation commands here like the one below??
android:screenOrientation="landscape"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "@drawable/sign"
>

<Button
android:id="@+id/Button1"
android.layout_height="60px"
android.layout_width="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Button1"/>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<Button
android:id="@+id/Button2"
android.layout_height="60px"
android.layout_width="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Button2"/>

Answer

add this line in your manifest.xml file.

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

if you want only landscape orientation then change landscape instead of portrait

see this How to set android show vertical orientation?

Comments