Dan
Dan

Reputation: 1110

Xamarin.Forms images not rendering

I am coding a Xamarin.Forms app that displays messages a user receives, which is displayed in a StackLayout with its body and an image for a like button.

My problem is when I have like 10 messages sometimes the image doesn't show for some of them. For example, it might render the image on each message except the fourth one.

This only seems to happen on Android, iOS renders the icon for each layout and they are using the same code.

My Code:

foreach (var message in messages)
{
    StackLayout childLayout = new StackLayout
    {
        BackgroundColor = Color.White,
        Margin = new Thickness(10, 10, 10, 0),
        Padding = new Thickness(10, 10, 15, 10),
        Spacing = 0,

    };
    Label body = new Label() { Text = message.Body };
    Image image = new Image() { Source = "like_icon.png" };

    //There are other children but not related to question

    childLayout.Children.Add(image);
    mainStackLayout.Children.Add(childLayout);
}

Upvotes: 1

Views: 804

Answers (1)

Steve Chadbourne
Steve Chadbourne

Reputation: 6953

As this is Android specific, it could be a memory issue as Android can quickly run out of memory when rendering images.

One workaround is to use the FFImageLoading plugin. This allows multiple image references using the same image source to use only one bitmap which greatly reduces the memory usage.

https://github.com/luberda-molinet/FFImageLoading

Upvotes: 1

Related Questions