我有这个:
<RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"></StackLayout>
</RelativeLayout>
但由于某些原因,即使很难看出RelativeLayout明显扩大,StackLayout也没有。如何让StackLayout水平拉伸并填充整个屏幕宽度/高度?
答案 0 :(得分:33)
对于RelativeLayout,您需要使用约束而不是Vertical / Horizontal选项。 应该像
<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>