2012-02-01 59 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> 

快樂編碼。