I have a GridLayout which contains several Button(s). All the Button(s) have a layout_gravity of center_horizontal, and the Button(s) in the first row have a column span of 2. In the Designer in Visual Studio 2019, this appears as follows:
In my code, I use the following code to rearrange the Button(s):
for (int btnindex = 1; btnindex < 5; btnindex++)
{
(this.grdBidsKeypad.GetChildAt(btnindex).LayoutParameters as GridLayout.LayoutParams).ColumnSpec = GridLayout.InvokeSpec(btnindex - 1, 2);
(this.grdBidsKeypad.GetChildAt(btnindex).LayoutParameters as GridLayout.LayoutParams).RowSpec = GridLayout.InvokeSpec(0);
}
for (int btnindex = 5; btnindex < 10; btnindex++)
{
(this.grdBidsKeypad.GetChildAt(btnindex).LayoutParameters as GridLayout.LayoutParams).ColumnSpec = GridLayout.InvokeSpec(btnindex - 5);
(this.grdBidsKeypad.GetChildAt(btnindex).LayoutParameters as GridLayout.LayoutParams).RowSpec = GridLayout.InvokeSpec(1);
}
for (int btnindex = 10; btnindex < 14; btnindex++)
{
(this.grdBidsKeypad.GetChildAt(btnindex).LayoutParameters as GridLayout.LayoutParams).ColumnSpec = GridLayout.InvokeSpec(btnindex - 9);
(this.grdBidsKeypad.GetChildAt(btnindex).LayoutParameters as GridLayout.LayoutParams).RowSpec = GridLayout.InvokeSpec(2);
}
(this.grdBidsKeypad.GetChildAt(14).LayoutParameters as GridLayout.LayoutParams).ColumnSpec = GridLayout.InvokeSpec(0);
(this.grdBidsKeypad.GetChildAt(14).LayoutParameters as GridLayout.LayoutParams).RowSpec = GridLayout.InvokeSpec(2);
this.grdBidsKeypad.ColumnCount = 5;
this.grdBidsKeypad.RowCount = 3;
However, this code ends up creating the following in the emulator:
It looks like either the layout_gravity is being reset or the layout_columnSpan (which, if I understand correctly, is the second parameter of InvokeSpec) is being ignored. What am I doing wrong?