我需要使用代碼動態生成表格佈局。我無法展示它。我已經將表代生成代碼段縮減爲其基本操作,試圖將它們排除在外,但即使這個大大簡化的版本也不起作用(即不顯示)。有人能指出我做錯了什麼嗎?謝謝。由代碼生成的TableLayout不顯示
public class TableByCodeTest extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TableLayout tableLayout = new TableLayout(this);
tableLayout.setLayoutParams(
new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TableRow firstTableRow = new TableRow(this);
firstTableRow.setLayoutParams(
new TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView title = new TextView(this);
title.setText(R.string.title);
title.setLayoutParams(
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
firstTableRow.addView(title);
tableLayout.addView(firstTableRow);
setContentView(tableLayout);
}
}
使用'hierarchyviewer'檢查你的UI來看看是怎麼回事錯。 – CommonsWare 2010-08-26 12:44:08