Listview Xamarin表单加载列表视图控件

Listview Xamarin表单加载列表视图控件,listview,xamarin.forms,ffimageloading,Listview,Xamarin.forms,Ffimageloading,我想使用带有ListView控件的FFImageLoading添加CacheDiImage。我已经在XAML上添加了三个包和控件,但是listview的显示速度仍然很慢。要使用listview控件,我还需要做些什么?我试着跟踪这个样本,但我不确定它是否有效 有没有办法确定图像是否被缓存 MainActivity.cs CachedImageRenderer.Init(true); FFImageLoading.Forms.Platform.CachedImageRenderer.Init(t

我想使用带有ListView控件的FFImageLoading添加CacheDiImage。我已经在XAML上添加了三个包和控件,但是listview的显示速度仍然很慢。要使用listview控件,我还需要做些什么?我试着跟踪这个样本,但我不确定它是否有效

有没有办法确定图像是否被缓存

MainActivity.cs

CachedImageRenderer.Init(true);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);
AppDelegate.cs

 CachedImageRenderer.Init();
XAML


.cs

公共类FastTemplateCell:ListViewTemplateCell
{
private FFImageLoading.Forms.CachedImage imageDownloadIcon;
私有FFImageLoading.Forms.CachedImage图像下载成功;
private FFImageLoading.Forms.CachedImage imageDownloadFailIcon;
受保护的覆盖无效OnBindingContextChanged()
{
base.OnBindingContextChanged();
这一点。确保删除();
如果(dataimageDownloadIcon!=null)
{
this.imageDownloadIcon.Source=“arrow\u start.png”;
}
如果(DataImageDownloadSuccessCon!=null)
{ 
this.imageDownloadSuccessIcon.Source=“circle\u done.png”;
}
如果(dataimageDownloadFailIcon!=null)
{
this.imageDownloadFailIcon.Source=“failed.png”;
}
}
私人无效担保
{
if(this.imageDownloadIcon==null)
{
this.imageDownloadIcon=this.View.FindByName(“imageDownloadIcon”);
}
if(this.imageDownloadSuccessIcon==null)
{
this.imageDownloadSuccessIcon=this.View.FindByName(“imageDownloadSuccessIcon”);
}
if(this.imageDownloadFailIcon==null)
{
this.imageDownloadFailIcon=this.View.FindByName(“imageDownloadFailIcon”);
}
}
}

根据您的描述和线程的标题,我不知道为什么在同一列中有三个图像,我猜您希望在列表视图中的ffimageloading中显示图像,如果是,我会编写一些代码供您查看:

首先,请安装Xamarin.FFImageLoading.Forms bu nuget包,然后您可以使用CacheDiImage

 <ListView HasUnevenRows="True" ItemsSource="{Binding images}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout>
                            <Label Text="{Binding title}" />
                            <ff:CachedImage Source="{Binding imagepath}" />
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

 public partial class Page4 : ContentPage
{
    public ObservableCollection<imagemodel> images { get; set; }
    public Page4()
    {
        InitializeComponent();
        images = new ObservableCollection<imagemodel>()
        {
            new imagemodel(){title="image 1",imagepath="a11.jpg"},
            new imagemodel(){title="image 2",imagepath="a12.jpg"},
            new imagemodel(){title="image 3",imagepath="a13.jpg"}
        };
        this.BindingContext = this;
    }
}
public class imagemodel
{
    public string title { get; set; }
    public string imagepath { get; set; }
}
和iOS AppDelegate的

FFImageLoading.Forms.Platform.CachedImageRenderer.Init();

关于自定义viewcell,我建议您可以查看自定义viewcell:


需要记住的一件事是图像的大小,如果您试图呈现一些大图像,即使它们被缓存,也可能需要一些时间才能加载到页面中,我以前遇到过这个问题,使用FFImage,您可以使用
DownsampleToViewSize
,您可以在,但这里是你需要知道的:

如果设置为true,则图像将调整为图像视图大小

因此,如果您的图像是1920x1080,但视图大小是例如:300x50,如果您将
DownsampleToViewSize
设置为
True
,它将为您缓存300x50版本,它将提高图像加载的速度,下面是XAML代码:

<ffimageloading:CachedImage
    LoadingPlaceholder="image_placeholder.png"
    Aspect="AspectFill"
    DownsampleToViewSize="True"
    Source="{Binding ThumnailImage}">
</ffimageloading:CachedImage>


回答你的问题:

有没有办法确定图像是否被缓存

我不确定您是否可以在内存使用中看到这一点,但您可以尝试将其与普通内存和缓存内存进行比较,看看在第二次加载图像时是否会更快。
就我所见,您已经为FFImageLoading正确安装了nuggets软件包。

您的listview中有多少元素?只有两个图像和标签。同一列中有三个图像将根据设置显示。您是否能够解决此问题,或者我是否可以添加答案!不,我还是不能解决这个问题issue@freakyAli你知道吗?@Jefferson,你试过我的样品吗?它在我这边运行得很好。我已经让它工作了,但是我如何确定它正在缓存图像,而不仅仅是读取每个图像time@Jefferson,如果您想查看,我建议您可以使用普通图像和缓存图像进行比较,这里是文章,您可以看一下:
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
<ffimageloading:CachedImage
    LoadingPlaceholder="image_placeholder.png"
    Aspect="AspectFill"
    DownsampleToViewSize="True"
    Source="{Binding ThumnailImage}">
</ffimageloading:CachedImage>