如何解决Xamarin中的ios的重叠列表
我正在做一个演示项目。我已经在xamarin视图中实现了listview并从API绑定了数据。首先,它看上去很合适,但是当我滚动列表时,列表开始重叠,并且在滚动到屏幕终点时变得越来越重叠。我尝试了各种解决方案,但没有得到解决方案。如果有人可以帮助我,那就太好了。 这是我的代码
id
解决方法
Xamarin.Forms通过ListViewCachingStrategy枚举允许ListView
单元格重复使用,该枚举具有以下值:
public enum ListViewCachingStrategy
{
RetainElement,// the default value
RecycleElement,RecycleElementAndDataTemplate
}
RecycleElement 缓存策略指定ListView
将尝试通过回收列表单元来最小化其内存占用和执行速度。
这里您需要使用CachingStrategy="RecycleElement"
才能解决此问题。
如下:
<ListView x:Name="UserListView"
VerticalOptions="FillAndExpand"
HasUnevenRows="True"
RowHeight="100"
IsVisible="true"
VerticalScrollBarVisibility="Never"
CachingStrategy="RecycleElement">
...
</ListView>
,
<DataTemplate>
<ViewCell>
<StackLayout>
<Frame BackgroundColor="Transparent" Padding="0" CornerRadius="0" Margin="0,-5,0" HeightRequest="100" HasShadow="False" BorderColor="Black">
<Frame IsClippedToBounds="True" VerticalOptions="Center" CornerRadius="0" Margin="0,-10,0" BackgroundColor="White" Padding="0" HeightRequest="90">
<StackLayout Orientation="Horizontal" Margin="15,15,15" >
<Image Source="image.png" />
<Label Text="{Binding id}" TextColor="Black" />
<Label Text="{Binding title}" TextColor="Black" />
<Label Text="{Binding userId}" TextColor="Black" />
<Label Text="{Binding completed}" TextColor="Black" />
</StackLayout>
</Frame>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
为我工作,方法是在框架内添加框架并将其设置为IsClippedToBounds =“ True”。 谢谢您的回答。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。