提问者:小点点

XamarInforms:RelativeLayout中的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水平拉伸并填充屏幕的整个宽度/高度?


共1个答案

匿名用户

对于RelativeLayout,您需要使用约束,而不是垂直/水平选项。应该是这样的

<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>