首页 > 解决方案 > Xamarin 在 iOS 中形成图像大小

问题描述

我在调整 iOS 设备中的图像大小时遇到​​了困难。我在 iOS 项目的 Resource 文件夹中放置了 3 张图片(forest.png、forest@2x、forest@3x)。使用不同的 iOS 设备,图像以相同大小显示

<Image Aspect="AspectFit" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Source="forest"/>

iOS

设备

森林森林@2x森林@3x

我做错了什么,或者需要修改什么?提前致谢

标签: iosxamarin.formsimage-size

解决方案


这应该是预期的行为,因为screen resolution/image size比率将相同。

如果要在所有屏幕上放置具有相同百分比面积的图像,请使用AbsoulteLayoutGrid放置。

(放置一个使用 60% 屏幕的图像):

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="3*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="3*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Image Grid.Row="1" Grid.Column="1" Source="Forest" Acpect="AspectFit"/>
</Grid>

推荐阅读