Android:线性布局 - 未指定垂直或水平



我正在学习一个教程,我注意到有一个线性布局,既没有指定垂直也没有水平。我在另一个教程中被告知它基本上是必需的......两者都没有意味着什么?不好吗?这被另一个线性布局所包围,它确实

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:id="@+id/group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add New" 
            android:onClick="onClick"/>
        <Button
            android:id="@+id/delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delete First" 
            android:onClick="onClick"/>
    </LinearLayout>
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
 </LinearLayout>

这只是意味着orientation默认为 horizontal .因此,如果属性不存在,则线性布局是水平线性布局。

当未指定 LinearLayout 的orientation时,它使用默认值,即 horizontal

根据官方文件:

安卓:方向

布局应该是一列还是一行?对行使用"水平",对列使用"垂直"。默认值为水平。

在 LinearLayout 的类概述中也提到了它:

类概述

将其子项排列在单列或单行中的布局...默认方向为水平方向。

而且在setOrientation()

公共空隙集方向(int 方向)

参数

方向           通过水平或垂直。默认值为水平。

线性布局的默认方向是"水平"

最新更新