我的列表视图数据模板中有互联网图像,如下所示。这是一个简单的 mvvm 绑定,我根本不使用任何代码。在列表视图上快速滚动时,它会被冻结。看起来它是由多次下载引起的。也许死锁(?)我正在使用 ffimageloading 但我尝试使用 XF 图像并且使用它也会出现问题。
我在 ffimageloading 的文档中看到,提到了 scrollstatechanged 事件,但我在 xamarin 表单列表视图中找不到它。似乎建议的解决方案是原生 android 级别。当然,不要在 XF 中使用它是有意义的,因为它是特定于 android 的。问题是如果这是解决方案,我该如何利用此事件?如果没有,这个问题还有其他解决方案吗?
我在 UWP 中测试过,fling 不会导致任何性能或冻结。
<DataTemplate>
<Grid ColumnSpacing="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ffimageloading:CachedImage RetryCount="1" TransparencyEnabled = "false" CacheDuration = "120"
LoadingPlaceholder="loading.png" FadeAnimationEnabled="True" CacheType="Disk"
InputTransparent="True" ErrorPlaceholder="thumb.png"
Source="{Binding Images, Converter={StaticResource thumbnailConvertor}}"
Aspect="AspectFit" Grid.Row="0" Grid.Column="0" />
<StackLayout Orientation="Vertical" Grid.Row="0" Grid.Column="1" >
<Label Text="{Binding name}" FontSize="20" FontAttributes="Bold"
</StackLayout>
</Grid>
</DataTemplate>
Xamarin Android 中的 ScrollStateChanged 事件
_
myListView.ScrollStateChanged += (object sender, ScrollStateChangedEventArgs scrollArgs) => {
switch (scrollArgs.ScrollState)
{
case ScrollState.Fling:
ImageService.Instance.SetPauseWork(true); // all image loading requests will be silently canceled
break;
case ScrollState.Idle:
ImageService.Instance.SetPauseWork(false); // loading requests are allowed again
// Here you should have your custom method that forces redrawing visible list items
_myListView.ForcePdfThumbnailsRedraw();
break;
}
};
编辑:Xamarin 使用 2.3.5 Pre6 形成
我尝试使用最新的预发布版本,因为 xamarin 声称使用快速渲染器进行了改进,但似乎情况变得更糟了。即使列表出现时不滚动,listview 也会立即冻结。