首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

动态平添tableview

2012-06-26 
动态添加tableviewTableLayout table(TableLayout)findViewById(R.id.shoppingCartTable)table.setBackg

动态添加tableview

        TableLayout table=(TableLayout)findViewById(R.id.shoppingCartTable);          table.setBackgroundColor(Color.BLACK);        TableLayout.LayoutParams params=new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,        TableLayout.LayoutParams.WRAP_CONTENT);         params.leftMargin =1;        params.rightMargin =1;        params.topMargin =1;        params.bottomMargin =1;        TableRow.LayoutParams params2 =  new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,        TableRow.LayoutParams.WRAP_CONTENT);         params2.leftMargin =2;        params2.rightMargin =2;        params2.topMargin =2;        params2.bottomMargin =2;                for(int i=0;i<20;i++){//20              TableRow row=new TableRow(this);              row.setLayoutParams(params);              row.setBackgroundColor(Color.BLUE);             row.setPadding(1, 1, 1, 1);                        for(int j=0;j<1;j++){//1                  TextView col=new TextView(this);                  col.setLayoutParams(params2);                col.setText("i="+i);                  col.setTextColor(0xFFFF0000);                 row.addView(col);//              }              table.addView(row);//          } 


这一段动态添加tableview的代码,保留下来以后说不定用的到

热点排行