ListView Xamarin.Forms(Android)中的图像溢出

有一个ListView,其中对于List的每个元素,您有3个按钮用于3个不同的选项,当您进入屏幕时,ImageButton的图像中没有溢出问题,但是当您第一次滚动时,源代码就会开始如下图所示溢出

ListView Xamarin.Forms(Android)中的图像溢出

当您向上或向下滚动时,图像会丢失中心并且未对齐,此问题在iOS中不会发生,仅在Android(版本6,7,8和9)中会发生,显然这是一个问题,例如Android渲染图片

我尝试过,将ImageButton控件更改为Button,问题仍然存在,还尝试将“ Aspect”属性分配给ImageButton,但是我没有获得成功的结果,如何解决此问题有帮助吗?然后我的代码XAML

   <ListView 
                ItemsSource="{Binding ListaRecintos}"
                Selectionmode="None"
                IsRefreshing="{Binding IsRefreshing,Mode=TwoWay}"        
                             RowHeight="80"
                             HasUnevenRows="True">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout
                                    Margin="0,4,0"
                                Orientation="Vertical">

                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="3.9*"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>


                                        <Label
                                            Text="{Binding Code}" 
                                            HorizontalOptions="Start" 
                                            FontSize="Small" 
                                            WidthRequest="40"
                                            HeightRequest="30"
                                            FontAttributes="Bold"
                                            VerticalTextAlignment="Center"
                                            HorizontalTextAlignment="Center"
                                            TextColor="{StaticResource das.color.texto}"
                                            VerticalOptions="CenterAndExpand"
                                            Grid.Column="0">
                                        </Label>

                                        <StackLayout Orientation="Vertical"
                                                      Grid.Column="1">
                                             <Label                                 
                                            Text="{Binding Name}"
                                            HorizontalOptions="Start" 
                                            FontSize="Small" 
                                            HeightRequest="32"
                                            MaxLines="2"
                                            TextColor="{StaticResource das.color.texto}"
                                            VerticalOptions="Center"
                                            VerticalTextAlignment="Center">
                                        </Label>
                                        </StackLayout>
                                    </Grid>

                                    <!--STACK BUTTON-->
                                    <StackLayout
                                              Orientation="Horizontal"
                                              HorizontalOptions="EndAndExpand"
                                              Margin="0,1,0">

                                        <!--BUTTON 1-->
                                        <ImageButton 
                                            Source="ic_check_wt"
                                            Aspect="AspectFit"
                                            CornerRadius="0"
                                            BackgroundColor="{StaticResource das.color.estado_success}"                                            
                                            HorizontalOptions="End"
                                            VerticalOptions="Center"
                                            HeightRequest="35"
                                            WidthRequest="50"
                                            commandparameter="2"
                                            Command="{Binding ControlAuditoriaCommand}"
                                            IsEnabled="{Binding EnabledButton}"/>

                                        <!--BUTTON 2-->
                                        <ImageButton 
                                            Source="ic_hammer"                                         
                                            BackgroundColor="{StaticResource das.color.estado_primary}"                                        
                                            HorizontalOptions="End"
                                            CornerRadius="0"
                                            Aspect="AspectFit"
                                            VerticalOptions="Center"
                                            HeightRequest="35"
                                            WidthRequest="50"
                                            commandparameter="1"
                                            Command="{Binding ControlAuditoriaCommand}"
                                            IsEnabled="{Binding EnabledButton}"/>

                                        <!--BUTTON 3-->
                                        <ImageButton 
                                            Source="ic_arrow_up"
                                            BackgroundColor="{StaticResource das.color.estado_success}"                                           
                                            HorizontalOptions="End"
                                            CornerRadius="0"
                                            Aspect="AspectFit"
                                            VerticalOptions="Center"
                                            HeightRequest="35"
                                            WidthRequest="50"
                                            commandparameter="3"
                                            Command="{Binding ControlAuditoriaCommand}"
                                            IsEnabled="{Binding EnabledButton}"/>

                                    </StackLayout>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

如何避免这种行为?对我有帮助吗?

angelafan 回答:ListView Xamarin.Forms(Android)中的图像溢出

我建议您使用(Frame + image)代替ImageButton,并在其上添加手势。

本文链接:https://www.f2er.com/3144717.html

大家都在问