Xamarin 按钮上的图像填充选项,在 Android 上看到溢出,但在 iOS 上看不到

sos*_*sil 3 xaml ios xamarin xamarin.forms

我们有一些带有图像的按钮,但我们只能在 iOS 上看到图像正确缩放。在 Android 上,图像溢出了按钮边界,因此我们基本上得到了图像的放大版本。

<Button VerticalOptions="CenterAndExpand" Grid.Column="1" Grid.Row="3">
     <Button.Image>
         <OnPlatform x:TypeArguments="FileImageSource"
             iOS="Revolutions_Button.png"
             Android="Revolutions_Button.png" />
      </Button.Image>
</Button>
Run Code Online (Sandbox Code Playgroud)

我什至尝试过HeightRequestWidthRequest即使有效,这也不是一个真正可行的解决方案,因为我不认为硬编码高度和宽度对于在不同屏幕尺寸上缩放是有意义的。但即使这些选项仅调整按钮容器的大小,图像的缩放比例仍然完全不同。

我们如何让图像缩放以适合 Android 上的按钮边界?

Jes*_*aya 6

您尝试过ImageButton控件吗?

<ImageButton VerticalOptions="CenterAndExpand"
             Grid.Column="1"
             Grid.Row="3"
             Aspect="AspectFit"
             Source="Revolutions_Button.png" />
Run Code Online (Sandbox Code Playgroud)