Skip to content

Instantly share code, notes, and snippets.

@darthdeus
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darthdeus/4ae71f71997ae1430477 to your computer and use it in GitHub Desktop.
Save darthdeus/4ae71f71997ae1430477 to your computer and use it in GitHub Desktop.
public class TestPage : ContentPage
{
ListView list;
Button button;
public TestPage()
{
list = new ListView { ItemsSource = new[] { "hello", "world", "from", "xamarin", "forms" } };
button = new Button { Text = "Button" };
// The same behavior happens for both Absolute and Relative layout.
var layout = true ? Relative() : Absolute();
Animate();
Content = layout;
}
Layout Relative()
{
var layout = new RelativeLayout();
layout.Children.Add(list,
Constraint.RelativeToParent(p => p.X),
Constraint.RelativeToParent(p => p.Y),
Constraint.RelativeToParent(p => p.Width),
Constraint.RelativeToParent(p => p.Height)
);
layout.Children.Add(button,
Constraint.Constant(0),
Constraint.Constant(300));
return layout;
}
Layout Absolute()
{
var layout = new AbsoluteLayout { Children = { list, button } };
AbsoluteLayout.SetLayoutBounds(list, new Rectangle(0, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutBounds(button, new Rectangle(0, 300, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
return layout;
}
async void Animate()
{
// Comment this delay out to see the bug
await Task.Delay(500);
button.LayoutTo(new Rectangle(100, 100, 100, 100), 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment