我已经在Xamarin.Forms项目定义的下列细胞类型:填充
public MyCell() // constructor
{
var messageLabel = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
FontAttributes = FontAttributes.Bold,
};
messageLabel.SetBinding(Label.TextProperty, new Binding("Message"));
var dateLabel = new Label
{
FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label))
};
dateLabel.SetBinding(Label.TextProperty, new Binding("Date"));
var view = new StackLayout
{
Children = { messageLabel, dateLabel },
Orientation = StackOrientation.Vertical,
};
View = view;
}
这被称为一个ListView内,像这样:
public MyPage()
{
var listView = new ListView()
{
ItemsSource = GetAllitems(),
ItemTemplate = new DataTemplate(typeof(MyCell)),
};
Content = listView
}
当这在屏幕上呈现出每个项目实际上已经与邻居压制在一起。我试图在MyCell类的StackLayout中添加填充,但这样做会导致文本离开屏幕。我想每个项目之间有差距。
我认为这可能是值得转换视图使用Xaml使这更清晰,所以如果它更容易实现Xaml我会接受这个答案!
你有没有试过设置'ListView'的RowHeight? –
这会修复所有人的身高吗?所以如果一个物品包装了一行文字,物品不会增加? – MartinM
try ti将以下内容添加到您的ListView中HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand,然后添加一个填充 –