0
我很新,Xamarin.Forms创建通用应用程序。其实我必须将一个大的原生应用程序迁移到Xamarin.Forms技术。Xamarin.Forms通用应用程序2列布局独立于设备大小
我必须创建一个独立于设备大小的双列布局(例如注册页面)。
我想使用RelativeLayout实现相同。代码同样是下面:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage BackgroundColor="Yellow" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LearningXamarin.Views.TestPage">
<ContentPage.Content>
<RelativeLayout>
<StackLayout x:Name="mainLayout" BackgroundColor="Maroon" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=0}">
<RelativeLayout>
<BoxView x:Name="firstView" BackgroundColor="Yellow" HeightRequest="30"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=5}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=20}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.48, Constant=0}"
/>
<BoxView BackgroundColor="Green" HeightRequest="30"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=firstView, Property=Width, Factor=1, Constant=10}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=firstView, Property=Y, Factor=1, Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=firstView, Property=Width, Factor=1, Constant=0}"
/>
</RelativeLayout>
</StackLayout>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
请建议是这样的正确的方式实现两个布局或有任何其他正确的方式。
我想尝试网格与两列,而不是 – Jason