【问题标题】:XamarinForms: StackLayout inside RelativeLayout is not filling the whole screenXamarin Forms:RelativeLayout 中的 StackLayout 没有填满整个屏幕
【发布时间】:2015-07-31 23:30:08
【问题描述】:

我有这个:

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

但由于某种原因,即使是硬的 RelativeLayout 明显扩展,StackLayout 也没有。如何让 StackLayout 水平拉伸并填充屏幕的整个宽度/高度?

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案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>
    

    【讨论】:

    • 我遇到了同样的问题,这个答案似乎不适用于 android。似乎对于其他子控件(例如网格)也很常见
    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多