Xamarin 如何使RelativeLayout.XConstraint平台特定

Xamarin 如何使RelativeLayout.XConstraint平台特定,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我在xamarin.forms中尝试相对布局,它在android中运行良好,但我在iOS中没有获得与相同值的正确对齐,是否有任何方法给出相对布局的平台规范 <RelativeLayout Grid.Row="0" VerticalOptions="StartAndExpand" HeightRequest="112.5"> <Image Source="close.png" Scale="0.3" RelativeLayout.XConstraint="{Constr

我在xamarin.forms中尝试相对布局,它在android中运行良好,但我在iOS中没有获得与相同值的正确对齐,是否有任何方法给出相对布局的平台规范

<RelativeLayout Grid.Row="0" VerticalOptions="StartAndExpand"  HeightRequest="112.5">
    <Image Source="close.png" Scale="0.3" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.25}">
        <Image.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding CancelPopUpCommand}"/>
        </Image.GestureRecognizers>
    </Image>
</RelativeLayout>

您可以添加依赖于平台的资源,并将您的因素绑定到其中:

<RelativeLayout Grid.Row="0" VerticalOptions="StartAndExpand"  HeightRequest="112.5">
    <RelativeLayout.Resources>
        <ResourceDictionary>
            <OnPlatform x:TypeArguments="x:Double" iOS="0.30" Android="0.25" x:Key="XFactor" />
        </ResourceDictionary>
    </RelativeLayout.Resources>
    <Image Source="close.png" Scale="0.3" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor={StaticResource XFactor}}">
        <Image.GestureRecognizers>
            <TapGestureRecognizer Command="{Binding CancelPopUpCommand}"/>
        </Image.GestureRecognizers>
    </Image>
</RelativeLayout>


来源:

添加您的问题“未获得正确对齐”的屏幕截图,以获得更多澄清。感谢您的重播@Dennis Schroer,我已经尝试过了,但没有得到我想要的东西,我通过以下方式解决了它:这很混乱,因为这与我的回答几乎相同,但方式不同,但很高兴您能成功。