安卓应用程序始终保持风景



我看过这里,但仍然无法解决我的问题。

我最近加入了安卓系统(头朝下(,一直在乱搞。我希望我的应用程序只在横向模式下运行,无论屏幕向哪个方向倾斜。

我的主屏幕基本上是一个有背景的页面,右边有几个对齐的按钮。

这是我的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"/>

在manifest.xml文件中添加此行。

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

如果你只想横向,那么改变横向而不是纵向

看到这个如何设置android显示垂直方向?

将以下属性添加到清单文件中的所有活动中:

android:screenOrientation="横向">

例如:

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

您可以将此属性添加到应用程序标记中,也可以添加到清单文件中。

希望这能帮助你解决你的问题。

您需要将android:screenOrientation="landscape"放在AndroidManifest.xml文件的activity标记上。

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

最新更新