【问题标题】:Set the Correct Image Dimension for Xamarin Forms为 Xamarin 表单设置正确的图像尺寸
【发布时间】:2022-01-12 09:24:33
【问题描述】:

我不知道如何确定在各种屏幕上以正确方式显示的正确图像尺寸,这是我的应用主页的示例:

我知道设备的屏幕因型号而异,我知道我可以设置Aspect="AspectFill" 来填充整个部分,但我不知道如何为每个设备指定图像大小适合所有屏幕尺寸并以正确方式显示的部分(例如:假设图像中有一个人,我希望该人出现在每个部分的中心)?

【问题讨论】:

  • 您必须为该图像设置修复高度和宽度。
  • @Divyesh_08 这就是我要问的问题,由于每个设备的屏幕不同,我如何确定宽度和高度?
  • 你计算一下。您可以从docs.microsoft.com/en-us/xamarin/essentials/…获取屏幕尺寸

标签: xamarin xamarin.forms layout xamarin.android xamarin.ios


【解决方案1】:

你可以使用Grid来实现这个效果。

定义Grid时,在设置行高和列高时使用*模拟百分比设置。

numbers + * 的总数表示您将行或列划分为多少个块。而在行或列的定义中,number + * 表示占用了多少块。这与百分比设置相同。

这里是xaml代码(复制粘贴看看效果):

<Grid Margin="20, 10, 20,10">
    <Grid.RowDefinitions>
        <RowDefinition Height="3*" />
        <RowDefinition Height="2*" />
        <RowDefinition Height="5*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="5*" />
        <ColumnDefinition Width="5*" />
    </Grid.ColumnDefinitions>
    
    <Label BackgroundColor="Blue" Grid.Row="0" Grid.ColumnSpan="2"></Label>
    <Label BackgroundColor="Green" Grid.Row="1"></Label>
    <Label BackgroundColor="Red" Grid.Row="1" Grid.Column="1"></Label>
    <Label BackgroundColor="Yellow" Grid.Row="2" Grid.ColumnSpan="2"></Label>
</Grid>

【讨论】:

  • 问题解决了吗?
猜你喜欢
  • 2014-10-09
  • 1970-01-01
  • 2017-08-15
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
相关资源
最近更新 更多