XamarinForms:RelativeLayout里面的StackLayout没有填满整个屏幕

时间:2015-05-19 22:47:55

标签: c# xaml xamarin xamarin.forms

我有这个:

<RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">
                <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"></StackLayout>
</RelativeLayout>

但由于某些原因,即使很难看出RelativeLayout明显扩大,StackLayout也没有。如何让StackLayout水平拉伸并填充整个屏幕宽度/高度?

1 个答案:

答案 0 :(得分:33)

对于RelativeLayout,您需要使用约束而不是Vertical / Horizo​​ntal选项。 应该像

<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"
     RelativeLayout.WidthConstraint=
         "{ConstraintExpression Type=RelativeToParent,
                                Property=Width,
                                Factor=1}"
     RelativeLayout.HeightConstraint=
         "{ConstraintExpression Type=RelativeToParent,
                                Property=Height,
                                Factor=1}">
</StackLayout>