首页 > 解决方案 > ffimageloading:CachedImage 图像不适合网格

问题描述

在此处输入图像描述

关于如何让我的图像适合网格的任何建议?下面是我的代码。

      <Grid   HorizontalOptions="FillAndExpand"
           VerticalOptions="FillAndExpand">
          <Grid.ColumnDefinitions>
           <ColumnDefinition Width="Auto" />
               </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition  Height="Auto" />
                        </Grid.RowDefinitions>
                        <ffimageloading:CachedImage 
                            x:Name="mainImage"  
                            Source="{Binding Image1}" 
                            LoadingPlaceholder= "LoaderImage"
                            ErrorPlaceholder= "{Binding Image2}"
                            CacheDuration= "50"
                            RetryCount= "3"
                            RetryDelay= "600"
                            DownsampleToViewSize = "true"                               
                            Grid.Column="0" 
                            WidthRequest="380" 
                            HeightRequest="380" 
                            Aspect="AspectFit">
                            <ffimageloading:CachedImage.Transformations>
                                <fftransformations:RoundedTransformation Radius="20"/>
                            </ffimageloading:CachedImage.Transformations>
                        </ffimageloading:CachedImage>
                    </Grid>

关于如何让我的图像适合网格的任何建议?

标签: xamlxamarinxamarin.androidxamarin.iosapp.xaml

解决方案


问题是由 你设置WidthRequest="380"的。HeightRequest="380"

图片的高度大于宽度。

因此,给出一个适当的 WidthRequest 和 HeightRequest 将解决如下问题:

 WidthRequest="320" 
 HeightRequest="480" 

更新

<Grid   HorizontalOptions="FillAndExpand"
       VerticalOptions="FillAndExpand">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition  Height="Auto" />
    </Grid.RowDefinitions>
    <ffimageloading:CachedImage  BackgroundColor="Red"
                        x:Name="mainImage"  
                        Source="logo.jpg" 
                        CacheDuration= "50"
                        RetryCount= "3"
                        RetryDelay= "600"
                        DownsampleToViewSize = "true"                               
                        Grid.Column="0" 
                                                                    
        Aspect="AspectFit">

    </ffimageloading:CachedImage>
</Grid>

推荐阅读