xamarin创建一个tablelayout,每行有2个按钮

时间:2017-05-07 16:59:08

标签: c# android xamarin tablelayout

我一直在尝试创建一个表格布局,旁边有两个按钮。我一直在看书,但是我似乎无法在屏幕上显示任何内容。这是我目前的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;
            }
        }

有什么建议吗?

提前感谢,

比约

0 个答案:

没有答案