我有以下内容LinearLayout
,我想在其中插入一些动态生成TableLayout
的 s。这运行没有任何错误,但屏幕上没有出现任何内容。为什么TableLayout
s没有出现?如何生成TableLayout
s 并将它们添加到 s 中LinearLayout
?
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/lblOverviewText">
</LinearLayout>
这就是我生成TableLayout
s 的方式:
var linearLayout = FindViewById<LinearLayout>(Resource.Id.linearLayout2);
foreach (var block in status.blocks)
{
var tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FillParent, TableLayout.LayoutParams.FillParent);
var rowParams = new TableLayout.LayoutParams(TableRow.LayoutParams.FillParent, TableRow.LayoutParams.WrapContent);
var tableLayout = new TableLayout(this);
tableLayout.LayoutParameters = tableParams;
TableRow tableRow = new TableRow(this);
tableRow.LayoutParameters =tableParams;
TextView textView = new TextView(this);
textView.Text = block.Name;
textView.LayoutParameters = rowParams;
tableRow.AddView(textView);
tableLayout.AddView(tableRow, rowParams);
linearLayout.AddView(tableLayout);
}