2012-09-24 98 views

回答

0

使用TableLayout表單xml並將xml充滿代碼。 現在你可以使用 addView(新的TableRow())...

添加新TableRows到tableLayout並再次U可以addView(視圖V)到每個錶行。 U可以addWeight每個tablerow的您添加到您的TableLayout..In情況

的TableRow重量爲2

addView(new TextView()) 
addView(new Spinner()) 
0

,只要你想,你可以添加許多表行:

"TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayoutFromXML);" 
"TableRow tableRow = new TableRow(this);" 
"tableRow.setLayoutParams(new LayoutParams(
          LayoutParams.FILL_PARENT, 
          LayoutParams.WRAP_CONTENT));" 
"tableRow.addView(WhatEver view that you want);" 
"tableLayout.addView(tableRow);" 

查看你想添加到表格,你也可以設置他們的屬性,如「寬度」或「高度」。

0

我知道我是有點晚了,但你可以試試這個.....

final TableLayout dynamicTable = (TableLayout) findViewById(R.id.hotelTableLayout); 

        /* Create a new row to be added. */ 
        final TableRow row = new TableRow(Hotels.this); 
        row.setLayoutParams(new TableRow.LayoutParams(
          TableRow.LayoutParams.MATCH_PARENT, 
          TableRow.LayoutParams.WRAP_CONTENT)); 

        /* Create a component to be the row-content. */ 
        SpnAdult = new Spinner(Hotels.this); 
        SpnAdult.setLayoutParams(new TableRow.LayoutParams(0, 
          TableRow.LayoutParams.WRAP_CONTENT, 1)); 
        SpnAdult.setAdapter(adapter); 

        /* Add Spinner to row. */ 
        row.addView(SpnAdult); 

        /* Add row to TableLayout. */ 
        dynamicTable.addView(row, new TableLayout.LayoutParams(
          TableLayout.LayoutParams.MATCH_PARENT, 
          TableLayout.LayoutParams.WRAP_CONTENT)); 

希望這有助於....