我正在学习Xamarin Forms中的listView,我想使用图像,但我只希望每行显示一个图像,但是当我运行我的代码时,它会同时显示所有图像。我附上了我的代码,你能不能帮我解决一下我的问题
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;
}
}
答案 0 :(得分:2)
您可以将stacklayout方向指定为垂直方向,还是创建一个包含三行&将每个图像分配到一行。