【问题标题】:Xamarin forms slow loading viewXamarin 形成缓慢加载视图
【发布时间】:2019-07-01 22:48:47
【问题描述】:

由于 xamarin 表单中的此功能,视图加载速度非常慢。 该函数加载存储在数据库中的大约 40 个不同的图像,并将它们放置在具有不透明度覆盖的绝对布局中。但是由于这种网格/绝对布局,视图加载速度非常慢。

 private void SetImages()
    {
        Grid cardGrid = new Grid();
        int column = 0;
        int row = 0;

        var tapGestureRecognizer = new TapGestureRecognizer();
        tapGestureRecognizer.Tapped += OnImageClick;
        FileImageSource opacitySource = new FileImageSource { File = "opacity.png" };

        foreach (var image in _cardImageHolder.CardImages)
        {
            image.Scale = 0.8;
            image.GestureRecognizers.Add(tapGestureRecognizer);

            Image opacity = new Image { Source = opacitySource, Scale = 0.8 };

            if (IsSelected(image))
            {
                opacity.Opacity = 0;
                image.Scale = 1;
            }

            _opacity.Add(image.CardId, opacity);
            var parent = new AbsoluteLayout{ Children = { image, _opacity[image.CardId] } };

            cardGrid.Children.Add(parent, column, row);

            if (column < 3)
            {
                column++;
            }
            else
            {
                column = 0;
                row++;
            }
        }

        scrollView.Content = cardGrid;
    }

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    您已经说过了,Xamarin.forms 仍然存在一些性能问题,如果您要加载图像(避免使用大图像),请使用延迟加载来加载它们,一次最多 5 或 10 个图像,如果您使用 Absolute Layout Xamarin 建议避免使用 AutoSize,这也将防止视图加载缓慢,我提高了使用最小图像尺寸加载图像视图的性能,我的主要观点是 40 个带有叠加层的图像加载视图太多了。

    【讨论】:

      【解决方案2】:

      尝试使用FFImageLoading。它像图像一样工作,但提供了更多有用的属性,并且具有良好的性能。图像在缓存中存储所需的时间,并为它们使用相同的位图源,这样可以节省大量内存。

      【讨论】:

        猜你喜欢
        • 2022-01-20
        • 1970-01-01
        • 2021-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-11
        • 2011-06-16
        相关资源
        最近更新 更多