ScrollView inside AbsoluteLayout not scrollable

I'm trying to create my own cool toolbar. In my toolbar, the buttons should seem like they hover above a background. I.e. they will overflow the background (bottom).

I'm wondering why the scrollview is not scrollable in my below code. And/or is there a smarter approach than using an AbsoluteLayout?

Kind regards, Emil

:)

public class AwesomeToolbar : AbsoluteLayout
{
    public AwesomeToolbar ()
    {
        HeightRequest = MinimumHeightRequest = 75;

        var scrollView = CreateScrollView();

        scrollView.Content = new StackLayout {
            Orientation = StackOrientation.Horizontal,
            Children = {
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
                new Button { Text = "Welcome to Xamarin Forms!", BackgroundColor = Color.Blue, MinimumHeightRequest = 75, HeightRequest = 75 },
            }
        };

        Children.Add(CreateGreyBackground());
        Children.Add(scrollView);
    }

    static BoxView CreateGreyBackground()
    {
        var greyBackground = new BoxView { BackgroundColor = Colors.Grey };

        AbsoluteLayout.SetLayoutBounds(greyBackground, new Rectangle(0, 0, 100, 50));
        AbsoluteLayout.SetLayoutFlags(greyBackground, AbsoluteLayoutFlags.WidthProportional);

        return greyBackground;
    }

    static ScrollView CreateScrollView()
    {
        var scrollView = new ScrollView { Orientation = ScrollOrientation.Horizontal };

        AbsoluteLayout.SetLayoutBounds(scrollView, new Rectangle(0, 0, 100, 75));
        AbsoluteLayout.SetLayoutFlags(scrollView, AbsoluteLayoutFlags.WidthProportional);

        return scrollView;
    }
Tagged:
Sign In or Register to comment.