2012-02-10 143 views
0

main.xml中文件代码:什么是“android:layout_column”属性?

<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手段这个孩子应该在哪一列的索引。我已经设置了两个CheckBoxandroid:layout_column = "1"属性,所以我认为这两个CheckBox都应该在第二列(索引:1)。但令我惊讶的是,第一CheckBox是在第二列,第二CheckBox是在第三列,就像你可以在下面看到: enter image description here

任何人都可以解释,为什么?

回答

2

您不能将两个Views放在同一列中。第一个CheckBox进入列1,因为您使用android:layout_column = "1"进行设置,第二个CheckBox自动放置在第2列。

编辑:如果你想在同一列中的复选框,你可以只用一个包裹LinearLayout它们,然后为LinearLayout设置android:layout_column = "1"