如何拉伸TextView
使其填满整个TableRow
高度?这是我现在所获得的截图,
我希望TextView
展开TableRow
。
以下是我创建行的方法:
row = new TableRow(this);
desc = new TextView(this);
desc.setBackgroundResource(R.drawable.borders);
desc.setTypeface(Typeface.SERIF, Typeface.BOLD);
desc.setText("Production Date");
desc.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT));
String date = gendataObj.getString("date");
text = new TextView(this);
text.setBackgroundResource(R.drawable.borders);
text.setText(date);
text.setGravity(Gravity.LEFT);
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT));
row.addView(desc);
row.addView(text);
table.addView(row, new TableLayout.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
答案 0 :(得分:4)
变化:
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT));
为:
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
除非另有说明,否则您不指定高度(只是宽度),默认情况下它将保持为WRAP_CONTENT
,这会导致TextView
与内容(文本)一样高。