Iam尝试在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>
答案 0 :(得分:1)
您可以添加与平台相关的资源并将您的因素绑定到它:
<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>