我在ffimageloading:CachedImage库中有一些图像的 ListView ...。
但是...在测试时,我会重复执行此操作:打开 ListView 并在确定的时间按操作栏上的“后退”按钮,当我按下“后退”按钮时,我有一个异常(exception):
在此错误之前,我还可以在输出中看到:
我更新了ffimageloading,但错误仍然在这里...我尝试了
MONO_GC_PARAMS=bridge-implementation=old
在环境txt中
这是我在PCL中的xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="neoFly_Montana.Views.ProdutosView"
xmlns:local="clr-namespace:neoFly_Montana.LayoutScripts"
xmlns:interface="clr-namespace:neoFly_Montana.Interface"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
BackgroundImage="prodBackground.jpg"
x:Name="ParentHost">
<ContentPage.Content>
<Grid HorizontalOptions="FillAndExpand" RowSpacing="0" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="9.4*"/>
<RowDefinition Height="0.6*"/>
</Grid.RowDefinitions>
<!-- Lista de produtos -->
<ListView Grid.Row="0" Grid.Column="0" ItemSelected="ListView_ItemSelected" CachingStrategy="RecycleElement" BackgroundColor="Transparent" x:Name="listview_produtos" Margin="10,0,10,0" SeparatorVisibility="None" HasUnevenRows="True" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<ListView.Header>
<!-- Observação -->
<StackLayout>
<StackLayout x:Name="prod_stack_obser" IsVisible="False" Orientation="Horizontal" Spacing="0" HorizontalOptions="FillAndExpand">
<Label x:Name="label_observ" HorizontalTextAlignment="Start" VerticalOptions="Center" FontSize="Small" TextColor="White" Style="{StaticResource labelsfont}" Margin="20,10,0,10" />
<ffimageloading:CachedImage x:Name="lapis" Source="lapis.png" IsVisible="False" HorizontalOptions="EndAndExpand"/>
</StackLayout>
<BoxView HeightRequest="20"/>
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="20,0,20,20">
<ffimageloading:CachedImage Source="texturaCateg.png" BackgroundColor="{Binding FundoColor, Source={x:Reference ParentHost}}" Grid.Row="0" Grid.Column="0" Aspect="Fill" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
<StackLayout Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" x:Name="produtos_stack_color" Spacing="10">
<StackLayout Spacing="0" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">
<StackLayout Orientation="Horizontal" Padding="10,10,10,0" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
<ffimageloading:CachedImage FadeAnimationForCachedImages="True" DownsampleUseDipUnits="True" DownsampleHeight="60" HeightRequest="83" WidthRequest="130" Source="{Binding imagem}" Aspect="Fill" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" >
<!--<ffimageloading:CachedImage.CacheKeyFactory>
<interface:CustomCacheKeyFactory/>
</ffimageloading:CachedImage.CacheKeyFactory>-->
</ffimageloading:CachedImage>
<!--HeightRequest="83" WidthRequest="100"-->
<!--DownsampleHeight="83"-->
<!--<StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="EndAndExpand">
<Label Style="{StaticResource labelsfont}" Text="R$" VerticalOptions="CenterAndExpand" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" FontSize="Medium"/>
<Label Style="{StaticResource labelsfont}" Text="{Binding valor}" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" FontAttributes="Bold" VerticalOptions="Start" FontSize="30"/>
</StackLayout>-->
</StackLayout>
<!--nome-->
<Label Text="{Binding nome}" Margin="0,10,0,10" Style="{StaticResource labelsfont}" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" HorizontalTextAlignment="Center" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="CenterAndExpand"/>
</StackLayout>
<Grid VerticalOptions="FillAndExpand">
<BoxView Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="WhiteSmoke" Opacity="0.2"/>
<Label Grid.Row="0" Grid.Column="0" Margin="10,10,10,10" HorizontalTextAlignment="Center" Text="{Binding observacao}" Opacity="1" FontSize="Small" Style="{StaticResource labelsfont}" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" HorizontalOptions="Center" />
</Grid>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<StackLayout>
<Grid x:Name="prod_rl_fundo" >
<Grid.Margin>
<OnPlatform x:TypeArguments="Thickness"
iOS="20,0,20,0"
Android="20,10,20,10"/>
</Grid.Margin>
<ffimageloading:CachedImage x:Name="prod_acomp_img" Source="texturaCateg.png" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" Aspect="Fill" VerticalOptions="FillAndExpand"></ffimageloading:CachedImage>
<!--Acompanhamentos-->
<StackLayout x:Name="stack_acompanhamentos" Spacing="0" Grid.Row="0" Grid.Column="0">
<Grid x:Name="prod_acompanhamentos_title" HorizontalOptions="FillAndExpand">
<BoxView Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="WhiteSmoke" Opacity="0.2"/>
<Label x:Name="produtos_acomp_title" Text="+ Dois Acompanhamentos" Grid.Row="0" Grid.Column="0" Style="{StaticResource labelsfont}" Margin="20,20,20,20" FontAttributes="Bold" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
</Grid>
</StackLayout>
</Grid>
<BoxView HeightRequest="50"></BoxView>
</StackLayout>
</ListView.Footer>
</ListView>
<!--Rodapé Grid-->
<Grid Grid.Row="1" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<ffimageloading:CachedImage Source="rodape.png"
HorizontalOptions="FillAndExpand"
Aspect="AspectFill"
VerticalOptions="FillAndExpand"
Grid.Row="0"/>
<!--Escrito Rodapé-->
<StackLayout Orientation="Horizontal"
Margin ="5,5,5,5" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Grid.Row="0">
<Label
FontSize="Micro"
Text="Você está em:"
Style="{StaticResource labelsfont}"
VerticalOptions="CenterAndExpand"
TextColor="White"/>
<Label FontSize="Micro"
Text="loja"
x:Name="prod_lbl_lojaprox"
Style="{StaticResource labelsfont}"
VerticalOptions="CenterAndExpand"
TextColor="{StaticResource laranjacolor}"
LineBreakMode="TailTruncation"
FontAttributes="Bold" />
</StackLayout>
</Grid>
</Grid>
</ContentPage.Content>
我的mainActivity:
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
//inicializa imageCircle
ImageCircleRenderer.Init();
//shared Preferences
App.Init(new AndroidUserPreferences());
//Gerenciador de memória
CachedImageRenderer.Init(true);
var config = new FFImageLoading.Config.Configuration()
{
VerboseLogging = false,
VerbosePerformanceLogging = false,
VerboseMemoryCacheLogging = false,
VerboseLoadingCancelledLogging = false,
FadeAnimationForCachedImages = false,
MaxMemoryCacheSize = 50000000,
FadeAnimationDuration = 500
//Logger = new CustomLogger(),
};
FFImageLoading.ImageService.Instance.Initialize(config);
LoadApplication(new App());
}
public override void OnTrimMemory([GeneratedEnum] TrimMemory level)
{
FFImageLoading.ImageService.Instance.InvalidateMemoryCache();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
base.OnTrimMemory(level);
}
public override void OnLowMemory()
{
FFImageLoading.ImageService.Instance.InvalidateMemoryCache();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
base.OnLowMemory();
}
我的图片是base64(png)
他们有8kb,它们是150x84像素
其中之一:
更新:我已经搜索了很多...我需要缓存键吗?
最佳答案
您是否在MainActivity中实现了InvalidateMemoryCache?在https://github.com/luberda-molinet/FFImageLoading/wiki/Advanced-Usage#clear-cache-and-memory-considerations上阅读更多内容
public override void OnTrimMemory([GeneratedEnum] TrimMemory level)
{
FFImageLoading.ImageService.Instance.InvalidateMemoryCache();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
base.OnTrimMemory(level);
}
public override void OnLowMemory()
{
FFImageLoading.ImageService.Instance.InvalidateMemoryCache();
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
base.OnLowMemory();
}
我认为问题出在您的base64逻辑上,但是让我们尝试一下。
关于listview - 在Android上出现内存不足错误的缓存图像(ffimageloading)-Xamarin Forms,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48990718/