【发布时间】:2014-03-17 16:17:21
【问题描述】:
我有一个表格布局,该表格包含两列 - 一个字段名称和一个字段值。在某些情况下,字段值是一个清单。我希望扩大“清单”行的行高,以便查看列表视图中的所有项目。
以下代码在一个微小的垂直可滚动视图中显示列表视图,与第一列中的字段名称高度相同。如何扩展行高以便查看整个列表? (表格单元格中的 FrameLayout 可以让我覆盖图标或文本)。
// get the table
TableLayout table = FindViewById<TableLayout>(Resource.Id.formTable);
// make a new table row
TableRow row = new TableRow(this);
// add the field name (left column)
TextView rowName = new TextView(this);
rowName.Text = field.Name + ":";
rowName.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
TableRow.LayoutParams tableLayoutParams = new TableRow.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.FillParent);
tableLayoutParams.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
tableLayoutParams.Weight = 1.0f;
tableLayoutParams.Width = 0;
row.AddView(rowName, tableLayoutParams);
// add the field value (right column - in this case, a listview for a checklist)
FrameLayout frameLayout = new FrameLayout(this);
List<string> strings = field.Items.ToList();
ListView listView = new ListView(this);
listView.Adapter = new ListViewFormAdapterCheckList(this, strings);
frameLayout.AddView(listView);
tableLayoutParams = new TableRow.LayoutParams(TableLayout.LayoutParams.WrapContent, TableLayout.LayoutParams.WrapContent);
tableLayoutParams.SetMargins(0, 10, 0, 0);
tableLayoutParams.Width = 0;
row.AddView(frameLayout, tableLayoutParams);
【问题讨论】:
标签: android android-layout listview android-listview tablelayout