2011-07-04 52 views
2

我看了Here但我仍然無法解決我的問題。Android應用程序始終停留在風景

我最近跳入android(headfirst)並且一直在搞亂。我希望我的應用程序只能在橫向模式下運行,而不管屏幕傾斜的方式。

我的主屏幕基本上是一個頁面,背景和幾個按鈕在右側對齊。

這裏是我的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"/> 
+0

bahh謝謝你們我正在改變錯誤的文件。我鏈接到的其他問題將解決這個問題 – sealz

回答

7

加入這一行中的manifest.xml文件。

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

如果你想那麼只有橫向變化,而不是縱向橫向

看到這個How to set android show vertical orientation?

+0

看來,這條線去哪裏我得到一個錯誤,如果不是它在加載時崩潰。 – sealz

3

添加以下屬性的所有activites在manifest文件:

機器人:screenOrientation =「landscape」

例如:

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

,你可以在你的應用程序標籤也manifest文件中添加該屬性。

希望這可以幫助您解決您的問題。

相關問題