布局是 Orientation =vertical 当设备旋转时它不会工作

Layout is Orientation =vertical when device rotate it wont work

我将以下布局设置为 Orientation = vertical。但是当我将模拟器旋转到 Landscape 时,它​​显示的是 Landscape 布局。

即使设备旋转到横向,我也希望布局处于垂直方向。

如何解决这个问题?感谢你的帮助。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/myLinearLayout"
    android:minWidth="25px"
    android:minHeight="25px">
    <TextView
        android:id="@+id/myLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Put Your Name here :" />
    <EditText
        android:id="@+id/myEditBox"
        android:inputType="textMultiLine"
        android:textColor="@android:color/background_dark"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hey! Click Me" />
</LinearLayout>



android:orientation="vertical"表示children垂直插入到布局中。因此,当您添加更多视图时,它们将相互堆叠。

垂直:

水平:

这是我使用的布局。尝试自己改变方向,看看效果:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <View
        android:background="#aabbdd"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <View
        android:background="#341233"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <View
        android:background="#123456"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <View
        android:background="#654321"
        android:layout_width="50dp"
        android:layout_height="50dp" />
    <View
        android:background="#550000"
        android:layout_width="50dp"
        android:layout_height="50dp" />
</LinearLayout>

如果您想在 Activity 中锁定旋转,您需要将以下 属性 添加到您的 Activity 属性中:

ScreenOrientation = ScreenOrientation.Portrait

所以它看起来像:

[Activity(Label = "Herp Derp", ScreenOrientation = ScreenOrientation.Portrait)]
public class HerpDerpActivity : Activity
{
    // more stuff here
}