當前位置:編程學習大全網 - 行動軟體 - android ui開發中,tablelayout的列數是怎麽計算的

android ui開發中,tablelayout的列數是怎麽計算的

TableLayout,表格布局采用行列形式管理UI組件,TableLayout不需要明確地聲明有多少行和列,而是通過添加TableRow、其它組件來控制表格的行數、列數。

每次向TableLayout添加壹個TableRow,就是在向表格添加壹行,TableRow也是容器,可以向TableRow中添加組件,每添加壹個組件,即是添加壹列。

如果直接向TableLayout添加組件,則認為這個組件占用壹行。

表格布局中列的寬度即是每壹列中最寬的組件的寬度。

使用前:

\

使用後:

\

<TableLayout

android:id="@+id/tableLayout1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:stretchColumns="*" >

<TableRow

android:id="@+id/tableRow1"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button

android:text="最近聯系人"

android:id="@+id/button4"

android:layout_width="1dip"

android:layout_height="wrap_content"></Button>

<Button

android:text="聯系人"

android:id="@+id/button5"

android:layout_width="1dip"

android:layout_height="wrap_content"></Button>

<Button

android:text="分組"

android:id="@+id/button5"

android:layout_width="1dip"

android:layout_height="wrap_content"></Button>

</TableRow>

</TableLayout>

<TableLayout

android:id="@+id/tableLayout1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:stretchColumns="*" >

<TableRow

android:id="@+id/tableRow1"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<Button

android:text="最近聯系人"

android:id="@+id/button4"

android:layout_width="1dip"

android:layout_height="wrap_content"></Button>

<Button

android:text="聯系人"

android:id="@+id/button5"

android:layout_width="1dip"

android:layout_height="wrap_content"></Button>

<Button

android:text="分組"

android:id="@+id/button5"

android:layout_width="1dip"

android:layout_height="wrap_content"></Button>

</TableRow>

</TableLayout>

TableLayout 增加壹個屬性 android:stretchColumns="*" 表示所有列都要自動拉伸,以便適應屏幕寬度。

它的值即可以是數字,也可以是*,註意數字是從0開始的,即:android:stretchColumns="1" 是設置 TableLayout所有行的第二列為擴展列。

上面我們會看到 第1列的按鈕比其他列的按鈕要寬,如果我們想都壹樣寬如何辦呢?

壹個簡單辦法:

android:layout_width="1dip"

  • 上一篇:夢見過新年的預兆
  • 下一篇:人生中第壹輛車——十四代軒逸,感謝相遇
  • copyright 2024編程學習大全網