A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
I think I found the answer. As it often is, it was simple carelessness. When rotating to portrait, I was setting the Width & Gravity, but I was not doing that when rotating to landscape (which is the code in this post was for). So once I added that, it seems to be good. Here is my final code:
for (int index = 0; index < homescreenbuttons.Count; index++)
{
bool islastrowbutton = (homescreenbuttons.Count % 2) == 1 && index == (homescreenbuttons.Count / 2);
(homescreenbuttons[index].LayoutParameters as GridLayout.LayoutParams).RowSpec = GridLayout.InvokeSpec(index % (homescreenbuttons.Count / 2 + homescreenbuttons.Count % 2));
(homescreenbuttons[index].LayoutParameters as GridLayout.LayoutParams).ColumnSpec =
GridLayout.InvokeSpec(index / (homescreenbuttons.Count / 2 + homescreenbuttons.Count % 2),
islastrowbutton ? 2 : 1, islastrowbutton ? GridLayout.Center : GridLayout.Fill, 1f);
(homescreenbuttons[index].LayoutParameters as GridLayout.LayoutParams).Width = islastrowbutton ? GridLayout.LayoutParams.WrapContent : 0;
(homescreenbuttons[index].LayoutParameters as GridLayout.LayoutParams).SetGravity(islastrowbutton ? GravityFlags.CenterHorizontal : GravityFlags.FillHorizontal);
}
this.incHomeScreen.RowCount = (homescreenbuttons.Count / 2) + (homescreenbuttons.Count % 2);
this.incHomeScreen.ColumnCount = 2;
Thanks for your help!