-
-
Save biapar/7bc193df444814bf759d25aa8aee4125 to your computer and use it in GitHub Desktop.
Xamarin Forms Parallax Scrolling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DemoPage : ContentPage | |
{ | |
public DemoPage () | |
{ | |
var image = new Image () { | |
Source = "http://eric.polerecky.com/images/abstract-1.jpg", | |
VerticalOptions = LayoutOptions.Start, | |
Scale = 3, | |
AnchorY = 0 | |
}; | |
var grid = new Grid (); | |
var scrollView = new ScrollView (); | |
scrollView.Scrolled += (object sender, ScrolledEventArgs e) => { | |
var imageHeight = image.Height * 3; | |
var scrollRegion = grid.Height - scrollView.Height; | |
var parallexRegion = imageHeight - scrollView.Height; | |
image.TranslationY = scrollView.ScrollY - parallexRegion * (scrollView.ScrollY / scrollRegion); | |
}; | |
scrollView.Content = grid; | |
grid.Children.Add (image); | |
StackLayout stackLayout = new StackLayout () { | |
HorizontalOptions = LayoutOptions.Center | |
}; | |
for (int i = 0; i < 50; i++) { | |
stackLayout.Children.Add (new Label () { | |
Text = "This is some text to scroll", | |
FontSize = 24, | |
HeightRequest = 50 | |
}); | |
} | |
grid.Children.Add (stackLayout); | |
this.Content = scrollView; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment