I\'m making an application in Xamarin forms but I have some trouble sticking a layout to the bottom of the device. I thought an AbsoluteLayout would work, but I cannot grasp
Here's a class I use to automate this. There's plenty of additions you can make by extending the class to having a scrollable center section (so it doesn't overlap the bottom if too long) etc!
public class CakeLayout : StackLayout
{
public CakeLayout()
{
TopStack = new StackLayout // TOP stack
{
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.Start
};
CenterStack = new StackLayout // CENTER stack
{
VerticalOptions = LayoutOptions.CenterAndExpand
};
BottomStack = new StackLayout // BOTTOM stack
{
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.End
};
Children.Add(TopStack);
Children.Add(CenterStack);
Children.Add(BottomStack);
}
public StackLayout BottomStack { get; private set; }
public StackLayout CenterStack { get; private set; }
public StackLayout TopStack { get; private set; }
}
Then to use this as a page, for example:
public class MyPage
{
public MyPage()
{
CakeLayout cakeLayout = new CakeLayout();
cakeLayout.TopStack.Children.Add(new Label { Text = "Hello Cake" });
cakeLayout.CenterStack.Children.Add(MyListView);
cakeLayout.BottomStack.Children.Add(MyButton);
// Assign the cake to the page
this.Content = cakeLayout;
...
}
...
}