4

如何拉伸它TextView以使其填充整个TableRow高度?这是我现在得到的截图,

我想TextViewTableRow.

这是我创建行的方式:

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));
4

1 回答 1

5

改变:

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的高度与其内容(文本)一样高。

于 2013-02-21T07:36:54.263 回答