2012-01-16 37 views
1

下面是一个表格布局按键部分为我的表行的XML代码:我怎样才能将表格行分成三个确切的部分?

<TableRow 
    android:id="@+id/tableRow8" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 
    <Button 
     android:id="@+id/buttonclear" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Clear" 
     android:layout_weight="1" android:textSize="18sp"/> 
    <Button 
     android:id="@+id/buttonback" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Back" 
     android:layout_weight="1" android:textSize="18sp"/> 
    <Button 
     android:id="@+id/buttonconfirm" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Confirm" 
     android:layout_weight="1" android:textSize="18sp"/> 

</TableRow> 

没有输入常数浸,我怎么会划分这些按钮均匀地分成三个? 虽然我没有尝试过重量但没有运气。

回答

2

您可能希望在TableLayout上使用android:stretchColumns属性。因为它是基于零的属性,所以它应该得到值“0,1,2”。

所以,你的XML应该大概如下所示:

<TableLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="0,1,2"> 
    <TableRow 
     android:id="@+id/tableRow8"> 
     <Button 
      android:id="@+id/buttonclear" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Clear" 
      android:textSize="18sp"/> 
     <Button 
      android:id="@+id/buttonback" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Back" 
      android:textSize="18sp"/> 
     <Button 
      android:id="@+id/buttonconfirm" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Confirm" 
      android:textSize="18sp"/> 
    </TableRow> 
</TableLayout> 

希望它能帮助。

+0

如果我在一个新的新的xml文件中尝试这个,它会工作, – 2012-01-16 15:28:00

+0

但如果我将它与我的一些表行(2columns,1 textview,1编辑文本)它会搞砸坏:( – 2012-01-16 15:28:41

+0

然后你需要在这个特定的TableRow(有2列的那个)的子节点之一上使用'android:layout_span'属性。它和HTML中的'colspan'一样。 – barthand 2012-01-16 17:42:37

0

您应该使用android:stretchColumns=*上的yout TableRow,也许你还想在你的TabelRow上设置android:layout_width="fill_parent"

相关问题