我有一個列表視圖,我想要顯示從URL加載的每個項目的圖像。如果我使用ImageCell作爲DataTemplate,它會加載一次,然後如果我嘗試再次加載,我會得到一個OutOfMemory錯誤。當在列表視圖中使用圖像時Xamarin.forms 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),但不幸的是它仍然不會第一次加載。
有沒有人有任何想法?
你的問題很不清楚。我看不出問題標題和描述之間的關係。 – 2014-10-08 11:44:50
對不起 - 已編輯,不知道我是如何管理的 – user1667474 2014-10-08 12:26:11