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的代码,保留下来以后说不定用的到
本文提供了一个使用TableLayout动态添加Tableview的代码示例,包括布局参数的设置和视图的添加过程,适合在Android应用开发中进行参考。

1920

被折叠的 条评论
为什么被折叠?



