Xaml Xamarin.Forms。优化列表视图
你能就如何优化ListView给出建议吗? 滚动时速度会减慢。 我的viewCell如下所示:Xaml Xamarin.Forms。优化列表视图,xaml,listview,xamarin.forms,Xaml,Listview,Xamarin.forms,你能就如何优化ListView给出建议吗? 滚动时速度会减慢。 我的viewCell如下所示: <Grid BackgroundColor="{Binding ListViewCustomizer.ItemBorderColor, Source={x:Static theme:ThemeManager.Theme}}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> <Grid Ma
<Grid BackgroundColor="{Binding ListViewCustomizer.ItemBorderColor, Source={x:Static theme:ThemeManager.Theme}}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid Margin="0, 0, 0, 1"
BackgroundColor="{Binding ListViewCustomizer.ItemBackgroundColor, Source={x:Static theme:ThemeManager.Theme}}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.Triggers>
<DataTrigger Binding="{Binding IsRead}" TargetType="Grid" Value="true">
<Setter Property="BackgroundColor" Value="#bfe3fa" />
</DataTrigger>
</Grid.Triggers>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<ContentView Grid.RowSpan="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="1, 1">
<ffimageloading:CachedImage x:Name="mainImage"
Source="news_placeholder.png"
LoadingPlaceholder="news_placeholder.png"
DownsampleToViewSize="false"
CacheDuration="{x:Static constant:ImageConfig.PreviewImageCacheDuration}"
ErrorPlaceholder="news_placeholder.png" Aspect="AspectFill"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Transformations="{Binding IsRead, Converter={StaticResource BoolToTransformationConverter}}">
<ffimageloading:CachedImage.DownsampleHeight>
<extensions:OnDeviceType x:TypeArguments="x:Double" Phone="130" Tablet="200"/>
</ffimageloading:CachedImage.DownsampleHeight>
</ffimageloading:CachedImage>
</ContentView>
<Grid Grid.Column="1" RowSpacing="0" Margin="10,10,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Label Style="{StaticResource BaseListItemLabelStyle}" FormattedText="{Binding ., Converter={StaticResource NewsItemToFormattedStringConveter}}"/>
<ctrl:ExtendedLabel
Grid.Row="1"
MultilineTrimming="True"
x:Name="content"
Style="{StaticResource ListItemContentLabelStyle}" />
</Grid>
</Grid>
</Grid>
也许可以用一些东西来代替一些东西。也许我应该用代码隐藏替换所有绑定
请帮帮我。你把很多东西塞进了可视单元。同时,将数据绑定更改为代码隐藏也不会在性能方面给您带来显著的好处 这里发生的是所有这些元素都需要运行布局过程,这需要时间(性能)。现在将其与ListView中的项目数量相乘。然而,好消息是,一旦你改进了你的视角,减少了布局,这个倍增因子将对你有利 我的建议是: 1) 不要使用“自动”高度定义,因为在确定最终高度之前,这将需要多个布局过程 2) 将轴网减少为一个轴网,并使用RowSpan和ColumnSpan属性来设置图元 3) 您使用内容视图有什么原因吗?如果我没记错的话,您应该能够将ffimageloading.cachedimage直接放入网格中 有关如何优化xamarin表单布局性能的更多信息,请参阅本文:“不要使用“自动”高度定义”。我可以用“*”(星型)吗?是的,因为“自动”会对孩子进行多次布局,以确定使用的高度。星获取父元素给定的可用空间的一小部分或全部。