【发布时间】:2017-10-05 15:54:24
【问题描述】:
我一直在尝试创建一个带有 2 个按钮的表格布局。我一直在阅读,但我似乎无法让它在屏幕上显示任何内容。这是我当前的 TableLayout 代码。
TableLayout ll = FindViewById<TableLayout>(Resource.Id.buttonLayout);
TableLayout llInner = new TableLayout(this);
TableLayout.LayoutParams lp = new TableLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);
llInner.Orientation = Orientation.Horizontal;
llInner.LayoutParameters = lp;
llInner.WeightSum = 2;
ll.AddView(llInner);
var i = 0;
var row = new TableRow(this);
//TableRow.LayoutParams rowlayout = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent);
row.LayoutParameters = lp;
foreach (var series1 in series)
{
var b = new Button(this);
b.Text = series1.Series;
//lp = new TableLayout.LayoutParams(1, LinearLayout.LayoutParams.WrapContent);
b.LayoutParameters = lp;
row.AddView(b);
i =+ 1;
if (i > 1)
{
llInner.AddView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.MatchParent, TableLayout.LayoutParams.WrapContent));
row = new TableRow(this);
row.LayoutParameters = lp;
i = 0;
}
}
有什么建议吗?
提前致谢,
比约恩
【问题讨论】:
-
您好,您为什么不尝试使用 .axml 页面。在 Xamarin 传统和 Xamarin 表单设计页面是优化的。而且非常有用。
-
sinds 需要创建的按钮数量是动态的,它基于我从 API 收到的信息。因此我不知道我需要创建多少个按钮。
标签: c# android xamarin tablelayout