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;
}