ContentPage包含列表视图在Android上显示非常慢
我不确定这是我的问题还是Xamarin的问题。 在iPad上,我的应用程序可以在ListView中加载包含数据列表的页面。 ListView内的View Cell可能稍微复杂一些。它包含一个配置文件图像,使用一些较小的图标,它们使用FFImageLoading。ContentPage包含列表视图在Android上显示非常慢
在iPad上,当我点击第一页的单元格进入包含数据列表的下一页时,它会非常顺利地加载。 在Android上,当我点击某个单元格进入下一页时,点击的检测速度很慢,并且ListView的加载时间也非常缓慢。
反正有提升性能吗?我认为这是我从SQLite加载的数据。但是,我注释掉ListView上的ItemsSource后,加载时间很好。
这是我用来显示单元格的数据素材。
<ViewCell>
<ViewCell.View>
<StackLayout Spacing="0" Padding="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" Spacing="10" Padding="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
<controls:CircleImage
Style="{StaticResource profileImageStyle}"
Margin="10, 10, 10, 10"
Source="{Binding Source}"
BorderColor="White"
BorderThickness="2"
VerticalOptions="Center"
HorizontalOptions="Center">
<controls:CircleImage.GestureRecognizers>
<TapGestureRecognizer Tapped="OnChildDetailTapped" />
</controls:CircleImage.GestureRecognizers>
</controls:CircleImage>
<StackLayout VerticalOptions="Fill" Spacing="1" Padding="0,20,0,10" HorizontalOptions="StartAndExpand">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnChildDetailTapped" />
</StackLayout.GestureRecognizers>
<StackLayout
Orientation="Vertical"
VerticalOptions="Center"
HorizontalOptions="StartAndExpand">
<Label x:Name="childName" Text="{Binding DisplayName}" Style="{StaticResource normalFont}"> </Label>
<local:ChildInfoIconsView
Child="{Binding .}"
VerticalOptions="Fill">
</local:ChildInfoIconsView>
<Label
x:Name="childNotes"
Style="{StaticResource footnoteFont}"
Text="{Binding ChildNotes, StringFormat={x:Static local:AppResources.formatNotes}}"
IsVisible="{Binding HasChildNotes}">
</Label>
<Label
x:Name="noPickupReason"
Style="{StaticResource footnoteFont}"
Text="{Binding NoPickupReason, StringFormat={x:Static local:AppResources.formatNoPickupReason}}"
IsVisible="{Binding HasNoPickupReason}">
</Label>
<Label
x:Name="absentReason"
Style="{StaticResource footnoteFont}"
Text="{Binding AbsentReason, StringFormat={x:Static local:AppResources.formatAbsentReason}}"
IsVisible="{Binding HasAbsentReason}">
</Label>
</StackLayout>
</StackLayout>
</StackLayout>
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="End">
<StackLayout.Padding>
<OnIdiom x:TypeArguments="Thickness">
<OnIdiom.Phone>5, 20, 10, 20</OnIdiom.Phone>
<OnIdiom.Tablet>10, 30, 30, 30</OnIdiom.Tablet>
</OnIdiom>
</StackLayout.Padding>
<Image
Style="{StaticResource listviewButtonStyle}"
IsVisible="{Binding EnabledSigning, Source={x:Reference page}}"
Source="ic_action_yes.png"
VerticalOptions="FillAndExpand"
HorizontalOptions="End">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnAttend" />
</Image.GestureRecognizers>
<Image.Margin>
<OnIdiom x:TypeArguments="Thickness">
<OnIdiom.Phone>0, 0, 5, 0</OnIdiom.Phone>
<OnIdiom.Tablet>5, 5, 20, 5</OnIdiom.Tablet>
</OnIdiom>
</Image.Margin>
</Image>
<Image
Style="{StaticResource listviewButtonStyle}"
IsVisible="{Binding EnabledSigning, Source={x:Reference page}}"
Source="ic_action_no.png"
VerticalOptions="FillAndExpand"
HorizontalOptions="End">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnAbsent" />
</Image.GestureRecognizers>
<Image.Margin>
<OnIdiom x:TypeArguments="Thickness">
<OnIdiom.Phone>5, 0, 0, 0</OnIdiom.Phone>
<OnIdiom.Tablet>20, 5, 5, 5</OnIdiom.Tablet>
</OnIdiom>
</Image.Margin>
</Image>
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
尝试设置列表视图缓存策略来提高性能。
See here更多细节
要知道,虽然你可能需要通过一些跳铁圈使用RecycleElement与FFImageLoading。问题描述here
此外,请发布您的数据模板,以便我们可以看到它是否可以简化。
是的,我使用这个RecycleElement,当我意识到滚动速度太慢..但这并不能帮助我导航到页面包含listview。 – LittleFunny
只需在顶层堆栈布局中放置一个TapGestureRecogniser,而不是在单元内放置多个TapGestureRecogniser。你也可以尝试在列表视图上绑定SelectedItem,而不是使用手势识别器。 –
数据模板中的布局非常复杂,并使用堆栈布局的负载。您应该能够通过使用5列的网格来大规模简化它。第二列中的标签可以保留在堆栈布局中。 –
使用RecyclerView
https://blog.xamarin.com/recyclerview-highly-optimized-collections-for-android-apps/
OR
使用FFImageLoading
https://github.com/luberda-molinet/FFImageLoading
优化和平滑滚动
如果有很多数据,也许尝试延迟加载 –
数据不是那么多的数据行9,但视图单元格需要显示配置文件和小图标。小图标只有24dp – LittleFunny
你尝试下采样图像? –