使用列表视图图像时Xamarin.forms OutOfMemory错误 [英] Xamarin.forms OutOfMemory error when using images in listview

查看:240
本文介绍了使用列表视图图像时Xamarin.forms OutOfMemory错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要显示的每个项目的图像,从URL加载列表视图。如果我使用的ImageCell作为DataTemplate中,它会加载一次,然后如果我尝试再次装入我会得到一个OutOfMemory错误。

I have a list view that I want to display an image for each item, loaded from a URL. If I use an ImageCell as the DataTemplate, it will load once and then if I try to load again I will get an OutOfMemory error.

我试过旁边从简介code到Xamarin窗体页这里<一个href=\"http://developer.xamarin.com/guides/cross-platform/xamarin-forms/introduction-to-xamarin-forms/\" rel=\"nofollow\">http://developer.xamarin.com/guides/cross-platform/xamarin-forms/introduction-to-xamarin-forms/创建一个自定义 ViewCell

I next tried the code from Introduction to Xamarin Forms page here http://developer.xamarin.com/guides/cross-platform/xamarin-forms/introduction-to-xamarin-forms/ to create a custom 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;
    }

}

但是,这不会加载即使加载列表中的第一次。

But that won't load the even load the list a first time

我试过Avrohom的code(这里找到<一href=\"http://stackoverflow.com/questions/25807196/xamarin-forms-listview-outofmemeoryerror-on-android?rq=1\">Xamarin.Forms在Android的ListView OutOfMemeoryError),但不幸的是它仍然不会加载第一次了。

I tried the Avrohom's code (found here Xamarin.Forms ListView OutOfMemeoryError on Android), but unfortunately it still won't load the first time.

有没有人有什么想法?

推荐答案

您的图像可能太大了,不是在文件大小的感觉,但这些文件的位图重新presentation。

Your images are probably way too big, not in the file-size sense, but the bitmap representation of those files.

您应该使用更小的图像,或者实现一个自定义单元格渲染器会替你在运行时。

You should use smaller images, or implement a custom cell renderer that does that for you at runtime.

这篇关于使用列表视图图像时Xamarin.forms OutOfMemory错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆