1

main.xml文件代码:

<TableRow 
android:id="@+id/TableRow01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
    <TextView 
    android:text="User" 
    android:id="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></TextView>

    <EditText 
    android:text="" 
    android:id="@+id/username" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"

    ></EditText>

    <TextView 
    android:text="Test" 
    android:id="@+id/usernameTest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"

    ></TextView>

</TableRow>

<TableRow 
android:id="@+id/TableRow05" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
>
    <TextView 
    android:text="Hobby" 
    android:id="@+id/hobby" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></TextView>

    <CheckBox 
    android:text="A" 
    android:id="@+id/reading" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_column="1"
    ></CheckBox>
    <CheckBox 
    android:text="B" 
    android:id="@+id/swimming" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_column="1"
    ></CheckBox>


</TableRow>

我查看了官方的 android 文档,从中了解到,这android:layout_column意味着这个孩子应该在的列的索引。我已经在两个CheckBox: 上设置了属性android:layout_column = "1",所以我认为这两个CheckBox应该都在第二列(索引:1)。但令我惊讶的是,第一个CheckBox在第二列,第二个CheckBox在第三列,如下所示: 在此处输入图像描述

谁能解释为什么?

4

1 回答 1

3

您不能将两个Views放在同一列中。第一个CheckBox在您设置的第 1 列中android:layout_column = "1" ,第二个 CheckBox 自动放置在第 2 列中。

编辑:如果您确实希望您的复选框在同一列中,您可以用 a 包装它们,LinearLayout然后android:layout_column = "1"为 that设置LinearLayout.

于 2012-02-10T06:37:06.663 回答