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”。 谢谢您的回答。