Android中的表格版面配置TableLayout,androidtablelayout
表格布局最主要的三個屬性:
XML代碼執行個體:
<?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" > <!-- 定義第一個表格版面配置,指定第2列允許收縮,第3列允許展開 --> <TableLayout android:id="@+id/TableLayout01" android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkColumns="1" android:stretchColumns="2" > <!-- 直接添加按鈕,它自己會佔一行 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ok1" android:text="獨" /> <!-- 添加一個表格行 --> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/ok2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普"/> <Button android:id="@+id/ok3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="收"/> <Button android:id="@+id/ok4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拉"/> </TableRow> </TableLayout> <!-- 定義第二個表格版面配置,指定第2列隱藏 --> <TableLayout android:id="@+id/TableLayout02" android:layout_marginTop="30dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:collapseColumns="1" > <!-- 直接添加按鈕,它自己會佔一行 --> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="獨" /> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="收"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拉"/> </TableRow> </TableLayout> <!-- 定義第三個表格版面配置,指定第2列和第三列允許被展開 --><TableLayout android:id="@+id/TableLayout03" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="1,2" android:layout_marginTop="30dp" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="獨" /> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普通按鈕"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拉"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拉"/> </TableRow> <!-- 定義一個表格行 --> <TableRow android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="拉"/> </TableRow></TableLayout></LinearLayout>
效果:
總結:
如果沒有用tableRow,直接用組件,將自己獨佔一行,並且填充父視窗
而如果用tableRow,上下兩行各列將對齊。
Android中TableLayout中的布局問題
使用weight屬性。將你控制項的layout中的width、height設定為fill-parent,
weight(權重)這個屬性很好的解決了這個問題。
android tablelayout布局填不滿螢幕怎辦???
樓主的tablelayout的高是怎麼設定的,是否用android:layout_height="fill_parent" ;
再者tablelayout是否嵌入在LinearLayout之中,如果的是話,LinearLayout的高是否也是android:layout_height="fill_parent" 。
只要tablelayout的高設定成填充滿父控制項,其父控制項也同樣如此設定tablelayout肯定能樸滿全屏目的。
那你的幾個TableRow的中有沒有用android:layout_weight="1",加入比重。