Search code examples
c#.netxamarinxamarin.formsscrollview

In Xamarin, should I be worried about displaying a large content within a scrollview?


I'm fairly new to Xamarin. I have a grid with 3 columns and many rows (the number of rows is not limited to a specific number) filled with images. This grid is placed within a scrollview. The thing is, I'm worried that I'll face memory exceptions for excessive amounts of rows.

Is this a thing that I should be concerned about or does Xamarin handle it "automagically". If so how should I approach to this problem? Note: I don't need all of the images loaded at the same time.


Solution

  • It would be better to use CollectionView if you want to display large number of similar items .

    CollectionView is a view for presenting lists of data using different layout specifications. It aims to provide a more flexible, and performant alternative to ListView.

    • CollectionView has a flexible layout model, which allows data to be presented vertically or horizontally, in a list or a grid.
    • CollectionView supports single and multiple selection.
    • CollectionView has no concept of cells. Instead, a data template is used to define the appearance of each item of data in the list.

    In your case , you just need to set the ItemsLayout as GridItemsLayout .

    <CollectionView ItemsSource="{Binding xxx}">
            <CollectionView.ItemsLayout>
                <GridItemsLayout ... />
            </CollectionView.ItemsLayout>
            
        </CollectionView>
    

    For more details you could check https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/collectionview/layout .