Can someone please explain the GridLayout references in Xamarin.Forms?
Using the example on FormsGallery, also seen here http://iosapi.xamarin.com/?link=T%3aXamarin.Forms.Grid (has an image too) I tried to work it out, but my trial and error hasn't been very successful, just very time-consuming.
Looking at the first row of the grid the code is as follows
grid.Children.Add(new Label
{
Text = "Grid",
Font = Font.BoldSystemFontOfSize(50),
HorizontalOptions = LayoutOptions.Center
}, 0, 3, 0, 1);
it looks to me as though the first 0 refers to the X position, the 3 refers to column span, the next 0 refers to y position and the one refers to row span. But using that as a reference and trying to add other rows and columns it doesn't work. It would be great if their samples included some comments, but as they don't could someone tell me how the GridLayout references work?
Cheers
I actually find the answer by Miha Markic a little misleading, not because of the answer he gave is incorrect but because what Xamarin does with those arguments isn't clear from the name.
Add(View view, int left, int right, int top, int bottom)
left = column,
right = used to work out column span ie. right - left
top = row,
bottom = used to work out row span ie. bottom - top
This means that if you want an item in the second column that span two you have to do this:
Add(view, 1, 3, 0, 1)
It's a bit weird as you need to put 3 in order to span two columns.
(I originally found the answer on the xamarin forum)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With