我已經在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,然後添加一個填充 –