1
votes

I'm new to Xamarin, so hopefully this is an easy fix. The problem is simple: I have a ScrollView containing a StackLayout, and adding new children to the StackLayout briefly causes the existing children to squish together causing a jittery visual disturbance. In the application I'm writing, children are being added to the StackLayout as the user scrolls down, so this jitter is also causing some more complicated issues with my scroll events.

The isolated issue is easy to reproduce:

<ScrollView>
    <StackLayout>
        <Button Clicked="Button_Clicked" Text="Click Me" HeightRequest="80"/>
        <StackLayout x:Name="Column1"/>
    </StackLayout>
</ScrollView>
private void Button_Clicked(object sender, EventArgs e)
{
    for (int i = 0; i < 5; i++)
        Column1.Children.Add(new Frame() { BackgroundColor = Xamarin.Forms.Color.Blue, HeightRequest = 100 });
}

Is there any way to create a scrollable view and add content dynamically without disrupting existing content? Any help would be much appreciated!

1
How about using a more appropriate control such as a CollectionView or ListView for this? Sounds like you are abusing ScrollView to have it do similar things.Cheesebaron
@Cheesebaron Thanks so much for pointing me in the right direction. The CollectionView gives me the ability to add children and scroll without visually disrupting existing content. If you wanted to post an answer I can definitely give you creditBrandon Church

1 Answers

1
votes

It would be much more appropriate to use a view such as a CollectionView or ListView to add children to a scrolling view on the fly. They are both more efficient in terms of only loading what is visible on the screen, and already have built in logic for adding/removing children such that the layout behaves nicely.

With CollectionView/ListView you can still have children that look differently, by using a TemplatSelector.