TableLayout看字面也知道是表格式的Layout,但是在android裡比較特別的是,TableLayout 只有到 TableRow,也就是一行、一行的換行,放在 TableRow 裡的控制項,自己會呈現水平式欄的狀態。

 程式執行結果:

tablelayout sample  

 

layout的xml檔程式:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

   

                    <TableLayout

                       android:id="@+id/tableLayout1"

                       android:layout_width="fill_parent"

                       android:layout_height="fill_parent"

                       android:stretchColumns="0,1,2" >

                       <TableRow>

                       <TextView

                         android:id="@+id/textView1"

                         android:layout_width="wrap_content"

                         android:layout_height="wrap_content"

                         android:text="@string/name" />

                       <EditText

                         android:id="@+id/editText1"

                         android:layout_width="200dip"

                         android:layout_height="wrap_content" />

                      </TableRow>                     

                     

                      <TableRow

                          android:id="@+id/tableRow1"

                          android:layout_width="wrap_content"

                          android:layout_height="wrap_content" >

                      <Button

                          android:id="@+id/button1"

                          android:layout_width="wrap_content"

                          android:layout_height="wrap_content"

                          android:text="@string/add" />

                      </TableRow>

                   </TableLayout>

               

</RelativeLayout>

arrow
arrow
    文章標籤
    android layout tablelayout
    全站熱搜
    創作者介紹
    創作者 jcgogo 的頭像
    jcgogo

    jcgogo

    jcgogo 發表在 痞客邦 留言(0) 人氣()