首页 文章

布局是方向=垂直当设备旋转它不工作

提问于
浏览
-1

我将以下布局设置为Orientation = vertical . 但是当我将模拟器旋转到横向时,它会显示横向布局 .

我希望布局在垂直方向上,即使设备旋转到横向 .

如何解决这个问题呢?感谢您的帮助 .

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

1 回答

  • 2

    android:orientation="vertical" 表示子项垂直插入到布局中 . 因此,当您添加更多视图时,它们将堆叠在彼此之下 .

    垂直:

    vertical

    水平:

    horizontal

    这是我使用的布局 . 尝试自行更改方向并查看效果:

    <?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中锁定旋转,则需要将以下属性添加到ActivityAttribute:

    ScreenOrientation = ScreenOrientation.Portrait
    

    所以它看起来像:

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

相关问题