Xamarin Forms:RelativeLayout 内的 StackLayout 未填满整个屏幕
XamarinForms: StackLayout inside RelativeLayout is not filling the whole screen
我有这个:
<RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"></StackLayout>
</RelativeLayout>
但出于某种原因,即使 RelativeLayout 明显展开,StackLayout 也不会。如何让 StackLayout 水平拉伸并填满整个 width/height 屏幕?
对于 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>
我有这个:
<RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0,15" Spacing="10"></StackLayout>
</RelativeLayout>
但出于某种原因,即使 RelativeLayout 明显展开,StackLayout 也不会。如何让 StackLayout 水平拉伸并填满整个 width/height 屏幕?
对于 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>