将视图添加到TableLayout会占用整个屏幕

时间:2011-12-30 20:10:22

标签: android xamarin.android tablelayout

我只是想在表格布局中的标题行下面添加一个分隔线,但无论我在layoutparams中设置宽度/高度,视图都会占用整个页面。

TableLayout tl = (TableLayout)FindViewById(Resource.Id.counted);
TableRow row = new TableRow(this);
TextView itemNumber = new TextView(this);
TextView itemDesc = new TextView(this);
TextView quantity = new TextView(this);

itemNumber.Text = "Item Number";
var inlo = new TableRow.LayoutParams(1);
inlo.SetMargins(10, 10, 30, 10);
itemNumber.LayoutParameters = inlo;

itemDesc.Text = "Item Description";
var idlo = new TableRow.LayoutParams(2);
idlo.SetMargins(10, 10, 30, 10);
itemDesc.LayoutParameters = inlo;

quantity.Text = "Quantity";
var qlo = new TableRow.LayoutParams(3);
qlo.SetMargins(10, 10, 30, 10);
quantity.LayoutParameters = qlo;

View v = new View(this);
v.LayoutParameters = new TableRow.LayoutParams(ViewGroup.LayoutParams.FillParent | 0);
v.SetBackgroundColor(Android.Graphics.Color.White);

row.AddView(itemNumber);
row.AddView(itemDesc);
row.AddView(quantity);

tl.AddView(row);
tl.AddView(v);

v及其白色背景占据了行下方的整个屏幕。 ????

1 个答案:

答案 0 :(得分:0)

刚决定使用字符串来强调我的列标题,而不是试图在第一行下面添加一行。