列表视图项目文本滚动更改

时间:2019-07-15 07:55:12

标签: c# listview xamarin xamarin.forms listviewitem

我有一个列表视图,其中我绑定了多个数据,例如标签和图像,并且我的框架中有该列表,所以当列表大小大于10个项目左右时,在滚动时,我的图像会自动调整其自身大小和标签文本开始隐藏隐藏。

这是我的xaml:

            <ListView 
                               x:Name="list" 
                               SelectionMode="None" 

                               SeparatorVisibility="None"
                               HasUnevenRows="True"
                               IsVisible="False"
                               BackgroundColor="Transparent"
                               ItemTapped="List_ItemTapped"
                               CachingStrategy="RetainElement"
                              >
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                            <Frame Padding="10" Margin="10">

                                                <Grid>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition 
        Height="Auto" />
                                                        <RowDefinition Height="*" 
        />
                                                    </Grid.RowDefinitions>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition 
        Width="Auto" />
                                                        <ColumnDefinition 
        Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <Label 
                                                        Grid.Row="0" 
                                                        Grid.Column="0"

                                                        Text="{Binding Note}" 
                                                        HorizontalOptions="Start"  
                                                        TextColor="Black"  
        FontSize="Small"
                                                        FontFamily=" 
       {StaticResource BoldFont}"
                                                        FontAttributes="Bold">
                                                    </Label>
                                                    <ImageButton
                                                         Grid.Row="0"  
                                                         Grid.Column="1"


        HorizontalOptions="EndAndExpand"
                                                        WidthRequest="22"
                                                        HeightRequest="22"
                                                        Padding="6"
                                                        Margin="0,0,0,0"
                                                        Clicked="btndelete"

        AbsoluteLayout.LayoutBounds="0,0,1,1"

        BackgroundColor="Transparent"
                                                        Source="close.png">
                                                    </ImageButton>
                                                    <Label 
                                                            Grid.Row="1"  
                                                            Grid.Column="0"

                                                            Text="{Binding 
        NOfQuestions}"
                                                            FontSize="12"
                                                            FontFamily=" 
       {StaticResource Regular}"
                                                            TextColor="White">

                                                    </Label>
                                                    <Label 
                                                            Grid.Row="1"  
                                                            Grid.Column="0"
                                                            Margin="15,0,0,0"

                                                            Text="{Binding 
        NOfDigits}"
                                                            FontSize="12"
                                                            FontFamily=" 
       {StaticResource Regular}"
                                                            TextColor="White">

                                                    </Label>
                                                </Grid>

                                            </Frame>
        </ViewCell>

                                </DataTemplate>
                            </ListView.ItemTemplate>
                          </ListView>

这是我在这个问题中遇到的视频,您可以看到列表看起来不错,但是当我开始滚动列表时,文本开始隐藏起来,隐藏起来,其大小发生变化,十字图像变小或变大,并在删除列表时项目所有文本消失

Gif video of my problem please watch this

3 个答案:

答案 0 :(得分:0)

尝试一下

 <ListView 
                       x:Name="list" 
                       SelectionMode="None" 
                       HorizontalOptions="FillAndExpand"
                       VerticalOptions="FillAndExpand"
                       SeparatorVisibility="None"
                       HasUnevenRows="True"
                       IsVisible="False"
                       BackgroundColor="Transparent"
                       ItemTapped="List_ItemTapped"
                       CachingStrategy="RetainElement"
                      >
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Frame Padding="10" Margin="10">

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition 
                                 Height="Auto" />
                                <RowDefinition Height="Auto" 
                                        />
                            </Grid.RowDefinitions>
                            <StackLayout Grid.Row="0" Orientation="Horizontal" HorizontalOptions="FillAndExpand" >


                                <Label                                                         
                                                Text="{Binding Note}" 
                                                HorizontalOptions="StartAndExpand"  
                                                TextColor="Black"  
                                                FontSize="Small"
                                                FontFamily=" 
                                                {StaticResource BoldFont}"
                                                FontAttributes="Bold">
                                </Label>
                            <ImageButton

                                                 HorizontalOptions="EndAndExpand"
                                                 WidthRequest="22"
                                                 HeightRequest="22"
                                                 Padding="6"
                                                 Margin="0,0,0,0"
                                                 Clicked="btndelete"  
                                                 AbsoluteLayout.LayoutBounds="0,0,1,1"    
                                                 BackgroundColor="Transparent"
                                                Source="close.png">
                            </ImageButton>




                            </StackLayout>



                            <StackLayout Grid.Row="1" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                <Label 

                                                    Text="{Binding 
                                                    NOfQuestions}"
                                                    HorizontalOptions="StartAndExpand" 
                                                    FontSize="12"
                                                    FontFamily=" 
                                                    {StaticResource Regular}"
                                                    TextColor="White">

                                </Label>
                                <Label 

                                                    Margin="15,0,0,0"    
                                                    Text="{Binding 
                                                    NOfDigits}"
                                                    HorizontalOptions="CenterAndExpand"
                                                    FontSize="12"
                                                    FontFamily=" 
                                                   {StaticResource Regular}"
                                                    TextColor="White">

                                </Label>
                            </StackLayout>

                        </Grid>

                    </Frame>
                </ViewCell>

            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

答案 1 :(得分:0)

这种重新呈现列表单元的行为通常与result = [*map(lambda x : list(x), result),] print(result) # [[5.8, 6.5, 7.6, 9.0], [13.5], [14.5, 18.1, 22.5], [25.7, 26.4, 30.7, 30.9, # 32.3], [33.6, 38.6, 38.8, 39.2, 40.6], [43.2], [47.9], [54.2], [60.3], [63.0]] 缓存策略有关。它定义了如何缓存单元,并在加载大量数据时尝试提高性能,但也可能使显示正确。尝试弄乱ListView。根据过去的经验,将其设置为“ RecycleElement”可以解决渲染问题。

另外,请检查this link以获得有关ListView性能的更多信息。

答案 2 :(得分:0)

ListView中有自定义单元格时,建议使用CachingStrategy

ListView是用于显示数据的强大视图,但是它有一些限制。使用自定义单元格时,滚动性能可能会受到影响,特别是当它们包含深度嵌套的视图层次结构或使用某些需要复杂测量的布局时。

Xamarin.Forms的XAML为不存在的属性提供XAML属性,该属性与缓存策略参数相对应:

<ListView CachingStrategy="RecycleElement" >
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <!-- ... -->
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>