我需要动态创建六个文本视图,但每个表格行只有三个文本视图,我需要放置两个表格行并分别放置三个文本视图
问问题
192 次
1 回答
0
尝试这样的事情。
TableLayout myTable=new TableLayout(this);
TextView[][] myTextView=new TextView[3][3];
myTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
TableRow[] myRow=new TableRow[3];
for (int i = 0; i < 3; i++) {
myRow[i]=new TableRow(this);
myRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
for (int j = 0; j < 3; j++) {
myTextView[i][j]=new TextView(this);
myTextView[i][j].setText("Your Text");
myRow[i].addView(myTextView[i][j]);
}
myTable.addView(myRow[i]);
}
LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
lin.addView(myTable);
于 2012-08-09T15:51:32.823 回答