1

The view is very slow to load because of this function in xamarin forms. The functon loads around 40 diffrent images that are stored in the database and place them in a absolute layout with a opacity overlay. But the view loads very slow because of this grid/absolute layout.

 private void SetImages()
    {
        Grid cardGrid = new Grid();
        int column = 0;
        int row = 0;

        var tapGestureRecognizer = new TapGestureRecognizer();
        tapGestureRecognizer.Tapped += OnImageClick;
        FileImageSource opacitySource = new FileImageSource { File = "opacity.png" };

        foreach (var image in _cardImageHolder.CardImages)
        {
            image.Scale = 0.8;
            image.GestureRecognizers.Add(tapGestureRecognizer);

            Image opacity = new Image { Source = opacitySource, Scale = 0.8 };

            if (IsSelected(image))
            {
                opacity.Opacity = 0;
                image.Scale = 1;
            }

            _opacity.Add(image.CardId, opacity);
            var parent = new AbsoluteLayout{ Children = { image, _opacity[image.CardId] } };

            cardGrid.Children.Add(parent, column, row);

            if (column < 3)
            {
                column++;
            }
            else
            {
                column = 0;
                row++;
            }
        }

        scrollView.Content = cardGrid;
    }

2 Answers 2

3

You have said it, Xamarin.forms still has some problems with performance, if you are going to load images (avoid using large images), load them with a lazy load, 5 or 10 images (at most) at a time, this will prevent the view to load slowly also if you are using Absolute Layout Xamarin recomends to avoid using AutoSize, I have increased the performance to load a view with images using the smallest image size posible, My main point is that 40 images with overlay is just too much to load a view.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use FFImageLoading. It works like an Image but provides a lot more helpfull properties, and it has good performance. Image are stored in cache for the desired time, and use the same bitmap source for them, which save a lot of memory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.