我一直在尝试创建一个表格布局,旁边有两个按钮。我一直在阅读,但我似乎无法让它显示任何东西在屏幕上。这是我当前的TableLayout代码。xamarin创建一个tablelaylay与每个行上的2个按钮
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形式设计页面是opmitise。而且非常有用。 –
sinds需要创建的按钮数量是动态的,它基于我从API接收到的信息。因此我不知道我需要创建多少个按钮。 –