开发者

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"/>


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?


Add the following property all the activites in your manifest file:

android:screenOrientation="landscape"

for example:

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

you can add this property in your application tag also in the manifest file .

hope this help you to solve your issue.


You need to put android:screenOrientation="landscape" on the activity tag in your AndroidManifest.xml file.

Reference: http://developer.android.com/guide/topics/manifest/activity-element.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜