2
我是iOS開發者,學習Xamarin Forms。如何使用Xamarin Forms將BoxView相對於另一BoxView居中
我想一個BoxView
相對於另一個BoxView
中心。這兩個盒子都像兄弟姐妹,加入其中,歷時RelativeLayout
。和第二框具有寬度的一半和所述第一框的高度的一半。我如何實現這一目標?
現在,我可以通過將HeighConstraint
和WidthConstraint
與Factor
相加來製作第一個盒子的第二個盒子。但我不知道如何中心這兩個觀點。在iOS中,我可以輕鬆地通過添加兩個約束來實現 - 以X爲中心,以Y爲中心。但是在Xamarin Forms中找不到類似的內容。
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PhoneWord.ExplorePage">
<ContentPage.Content>
<RelativeLayout>
<BoxView
x:Name="GrayBox"
Color="Gray"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.4}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}">
</BoxView>
<BoxView
BackgroundColor="Yellow"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=GrayBox, Property=X, Constant=100}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, ElementName=GrayBox, Property=Y, Constant=50}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToView, ElementName=GrayBox, Property=Height, Factor=0.5}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=GrayBox, Property=Width, Factor=0.5}">
</BoxView>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>