sga*_*dev 16 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>
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,即使相对布局明显扩大,StackLayout也没有.如何让stacklayout水平拉伸并填充整个屏幕宽度/高度?
Art*_*nov 35
对于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>
Run Code Online (Sandbox Code Playgroud)