Android 动态 TableRow setLayoutParams 不工作
Android dynamic TableRow setLayoutParams not working
我的 xml 中有一个 TableLayout,我可以在我的 TableLayout 中动态添加带有 TextView 的 TableRow,但问题是,宽度和高度没有设置为我设置的值。
TableRow tr = new TableRow(this);
tr.setPadding(0, 10, 0, 0);
TextView labelTV = new TextView(this);
labelTV.setText(strWork);
labelTV.setTextColor(Color.parseColor("#D69E29"));
labelTV.setTextSize(16);
labelTV.setLayoutParams(new TableRow.LayoutParams(
130,
TableRow.LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
mTable.addView(tr);
改成这样
TableRow.LayoutParams prms = new TableRow.LayoutParams(130,TableRow.LayoutParams.WRAP_CONTENT)
tr.addView(labelTV,prms);
希望对您有所帮助。
我的 xml 中有一个 TableLayout,我可以在我的 TableLayout 中动态添加带有 TextView 的 TableRow,但问题是,宽度和高度没有设置为我设置的值。
TableRow tr = new TableRow(this);
tr.setPadding(0, 10, 0, 0);
TextView labelTV = new TextView(this);
labelTV.setText(strWork);
labelTV.setTextColor(Color.parseColor("#D69E29"));
labelTV.setTextSize(16);
labelTV.setLayoutParams(new TableRow.LayoutParams(
130,
TableRow.LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
mTable.addView(tr);
改成这样
TableRow.LayoutParams prms = new TableRow.LayoutParams(130,TableRow.LayoutParams.WRAP_CONTENT)
tr.addView(labelTV,prms);
希望对您有所帮助。