2012-02-01 55 views
0

首先,XML如下:困惑在TableLayout “FILL_PARENT”

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <TableLayout 
     android:layout_width = "wrap_content" 
     android:layout_height = "wrap_content" 
     android:stretchColumns = "1"> 

     <TableRow> 
      <TextView 
       android:text = "Test Layout:" 
       android:id = "@+id/LayoutTextView01" 
       android:layout_width = "wrap_content" 
       android:layout_height = "wrap_content" 
       android:textColor = "@color/red_bg" /> 
      <EditText 
       android:text = "" 
       android:id = "@+id/EditText01" 
       android:layout_width = "fill_parent" 
       android:layout_height = "wrap_content" /> 
     </TableRow> 

     <TableRow android:gravity = "right"> 
      <Button 
       android:text = "test" 
       android:id = "@+id/layoutButton01" 
       android:layout_width = "fill_parent" 
       android:layout_height = "wrap_content" /> 
     </TableRow> 

    </TableLayout> 


</LinearLayout> 

我的问题是:

1. fill_parent手段填补其父容器的所有空间。而按钮的父母应该有EditView中的父母相同的尺寸,并为按钮EditView中两集的android:layout_width为“FILL_PARENT”,他们应该有相同的大小,就像这样:

________ ___________________ 
|_______| |__________________| 
       __________________ 
      |__________________| 

但结果是这样的:

________ ___________________ 
|_______| |__________________| 
         ___________ 
         |__________| 

为什么?

回答

0

如果您将android:layout_column="1"添加到您的button tag也许会有所帮助。

顺便说一句。我如何称赞问题而不是提交答案?

+0

感谢您的回答。 IOW android只会选择属于第0列的按钮,因此按钮的大小与TextView相同,对不对?顺便说一句,在每个问题下面都有一个“添加评论”链接,您可以通过该链接添加评论。在每个问题的左侧,都有一个五角星,你可以点击它来收藏它。还有一个△▽,帮助你上下一个问题。 – Searene 2012-02-03 03:27:53

+0

在每个问题和下面的答案下,都有一个“添加注释”链接... – FallenAngel 2012-02-04 16:00:24

0

问题是你的按钮认为它在列0中。如果添加另一个元素,它将在第1列中并具有相同的宽度。我试了一下,这应该会给你你正在寻找的结果。

<TableRow android:gravity = "right"> 
     <TextView 
      android:text = "" 
      android:layout_width = "wrap_content" 
      android:layout_height = "wrap_content" /> 
     <Button 
      android:text = "test" 
      android:id = "@+id/layoutButton01" 
      android:layout_width = "fill_parent" 
      android:layout_height = "wrap_content" /> 
</TableRow> 

快乐编码。