標籤:
1.先把XML內的預設RelativeLayout排版方式清空,在去Layout區拉一個TableLayout的到表單上,XML下會出現下面程式碼 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="2" > (android:stretchColumns="2"是設定 TableLayout所有行的第二列是擴展列,列是指上下,行是左右,假設每行都有三列(三個物件),剩下空間會由第二列補齊,下面會做示範) </TableLayout> 2.在Layout拉一個TableRow出來,在TableLayout標籤之間會夾著TableRow <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="2" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > </TableRow> </TableLayout> 3.在去widget拉一個物件button出來,如圖片接下來再拉一個buttonOK,還是沒變化因為android:stretchColumns="2"是設定第二列才開始填滿,好!在拉一次button我們發現真的在第二列開始填滿剩下的空間了!也就是剩下空間會由第二列補齊(最左邊是第0列,以此類推)
介面排版-TableLayout的stretchColumns方法