2012-06-30 24 views
0

我是Android開發新手。
我有一個活動,我想在兩個表格行中設置幾個按鈕。但目前他們只用它
一小部分,下面是佈局此類活動的XML:
如何使表格單元格在TableLayout中使用所有屏幕高度?

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </TableRow> 


    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
    </TableRow> 

</TableLayout> 

感謝您的幫助!

回答

1

嘗試使用Android:layout_weight = 「1」,在錶行

<TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

看到這個

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#ffff0000"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </TableRow> 


    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
      android:background="#ff00ff00"> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
      android:background="#ff00ff"> 
    </TableRow> 

</TableLayout> 

enter image description here

+0

這次沒help.They仍然不佔據整個屏幕的高度。 –

+0

感謝您的努力,您還需要爲每個按鈕設置layout_height =「0dp」,這樣如果您有3行,它們將佔用屏幕高度的三分之一。 –

+0

對不起,但是你想讓所有三行不僅填滿屏幕尺寸嗎? –

0

它這樣....

  1. 要麼轉到GUI工具來編輯Eclipse中的XML屬性並設置佈局屬性 layout weight to 1

    或GOTO XML頁面,並執行以下操作以錶行android:layout_weight="1" android:layout_width="wrap_content"android:layout_height="wrap_content"

+0

佈局的layout_width和layout_height如何?我是否需要將它們設置爲其他內容,或將其保存爲fill_parent? –

+0

android:layout_width =「wrap_content」和android:layout_height =「wrap_content」我沒有提及他們,認爲它很明顯,你會實現它...對不起 –

相關問題