【发布时间】:2014-12-02 21:56:56
【问题描述】:
我有一个列表视图,我想显示从 URL 加载的每个项目的图像。如果我使用 ImageCell 作为 DataTemplate,它将加载一次,然后如果我再次尝试加载,则会收到 OutOfMemory 错误。
接下来我尝试使用 Xamarin 表单简介页面 http://developer.xamarin.com/guides/cross-platform/xamarin-forms/introduction-to-xamarin-forms/ 中的代码来创建自定义 ViewCell
class MyViewCell : ViewCell
{
public MyViewCell()
{
var image = new MyImage
{
HorizontalOptions = LayoutOptions.Start
};
image.SetBinding(Image.SourceProperty, new Binding("ImagePath"));
image.WidthRequest = image.HeightRequest = 40;
var nameLayout = CreateLayout();
var viewLayout = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Children = { image, nameLayout }
};
View = viewLayout;
}//end constructor
static StackLayout CreateLayout()
{
var titleLabel = new Label
{
HorizontalOptions= LayoutOptions.FillAndExpand,
TextColor = Color.FromRgb(0, 110, 128)
};
titleLabel.SetBinding(Label.TextProperty, "Title");
var detailLabel = new Label
{
HorizontalOptions = LayoutOptions.FillAndExpand
};
detailLabel.SetBinding(Label.TextProperty, "Detail");
var layout = new StackLayout()
{
HorizontalOptions = LayoutOptions.StartAndExpand,
Orientation = StackOrientation.Vertical,
Children = { titleLabel, detailLabel }
};
return layout;
}
}
但这不会加载甚至第一次加载列表
我尝试了 Avrohom 的代码(在此处找到 Xamarin.Forms ListView OutOfMemoryError exception on Android),但不幸的是它仍然无法在第一次加载。
有人有什么想法吗?
【问题讨论】:
-
你的问题很不清楚。我看不到问题标题和描述之间的关系。
-
抱歉 - 已编辑,不确定我是如何处理的
标签: listview out-of-memory xamarin.forms