user9487391
user9487391

Reputation: 91

How can I display a single image in each row in xamarin

I am learning about listView in Xamarin Forms, and I want to use images, but I only want to display one image per row, but when I run my code, it displays all images at the same time. I have attached my code, so could you please help me how I can fix it

public class image: ViewCell
{
    public image()
    {
        var image = new Image
        {
            Source = ImageSource.FromFile("image1.png"),
            HeightRequest = 50,
        };
        var image1 = new Image
        {
            Source = ImageSource.FromFile("image2.png"),
            HeightRequest = 50,
        };
        var image2 = new Image
        {
            Source = ImageSource.FromFile("image3.jpg"),
            HeightRequest = 50,
        };



        var stackLayout = new StackLayout
        {
            Padding = new Thickness(20, 5, 5, 5),
            Orientation = StackOrientation.Horizontal,
            Children = {
                image, image1, image2,
                new Label { Text = "images", VerticalOptions = 
                LayoutOptions.Center }
            }
        };

        View = stackLayout;
    }
}

Upvotes: 0

Views: 104

Answers (1)

Manasa
Manasa

Reputation: 120

Can you give stacklayout orientation as vertical or create a Grid with three rows & assign each image to one row.

Upvotes: 2

Related Questions