2011-05-02 35 views
2

我在我的Android應用程序佈局如下:如何在Android中擴展TableLayout的中間TableRow?

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout android:id="@+id/widget41" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical"> 
<tablerow> 
    <Button android:id="@+id/button_when" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:padding="10px" 
     android:text="When"> 
    </Button> 
</tablerow> 
<tablerow> 
    <EditText android:id="@+id/text_description" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:padding="10px" 
     android:text="What happened?" android:textSize="18sp"> 
    </EditText> 
</tablerow> 
<tablerow> 
    <Button android:id="@+id/button_location" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:padding="10px" 
     android:text="Location"> 
    </Button> 
</tablerow> 

我怎樣才能讓我的佈局,以便在中間,一個用的EditText,展開以填充的整個空間屏幕沒有被第一個和第三個項目佔用?

回答

0

這很簡單。

有兩種方式

  1. 找出屏幕密度和分辨率,然後找出多少空間是由第一個和最後需要。
  2. 現在只需使用android:layout_height="space which has been left"

另一種方式分配的空間,你中間行的其餘部分是改變的android:layout_height直到它覆蓋整個屏幕

我個人的意見是去與1號一個是因爲屏幕尺寸可以是不同的設備,所以你應該玩安全。

順便問一下,你確定你的代碼工作?因爲您的t在您的標籤<tablerow>中使用小寫字母,因此它應該是<TableRow>。如果你不會在每個標籤中通過android:layout_height and android:layout_width,那麼它可能會導致佈局錯誤。

玩安全,否則你的應用程序將成爲越野車。

我希望這會有所幫助。

+0

你可能會看看我的答案。 – Martin 2011-07-28 12:22:31

1

這可以做的更簡單,然後從Varundroid的建議。 android.widget.TableRowandroid.widget.LinearLayout的子類,因此可以採用佈局可以採用的所有參數。因此,這將這樣的伎倆:

<TableRow 
    android:layout_height='fill_parent' 
    android:layout_weight='1.0' 
    android:layout_width='fill_parent' 
    > 
    … 
    </TableRow> 

注意,需要擴大時,通常需要設置android:layout_weight

相關問題