首页 文章

Xamarin表格 - 相对布局 - 将第一个视图的顶部与第二个底部对齐,而不将它们添加到垂直StackLayout中

提问于
浏览
1

我需要在相对布局中添加视图 .

我需要将它们相对于彼此的边缘垂直/水平对齐 . 不是关于父视图 .

但似乎Xamarin相对布局API只能提供相对于父 RelativeToParent 的相对布局对齐 .

2 回答

  • 0

    xamarin表单支持RelativeToView

    <RelativeLayout>
        <BoxView x:Name="topBox" 
                 Color="Red"
                 RelativeLayout.WidthConstraint ="{ConstraintExpression
                      Type=RelativeToParent,
                      Property=Width,
                      Factor=0.6,
                      Constant=0}"
                 RelativeLayout.XConstraint ="{ConstraintExpression
                      Type=RelativeToParent,
                      Property=X,
                      Constant=20}" />
    
        <BoxView 
            Color="Blue"
            RelativeLayout.WidthConstraint ="{ConstraintExpression
                Type=RelativeToParent,
                Property=Width,
                Factor=0.6,
                Constant=0}"
            RelativeLayout.YConstraint="{ConstraintExpression
                Type=RelativeToView,
                ElementName=topBox,
                Property=Y,
                Constant=40}"
            RelativeLayout.XConstraint="{ConstraintExpression
                Type=RelativeToView,
                ElementName=topBox,
                Property=X,
                Constant=0}" /> 
    </RelativeLayout>
    

    enter image description here

    希望能帮助到你

  • 1

    正如Kojan指出的那样,有 Constraint.RelativeToView .

    对于XAML和C#示例,请查看:https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/relative-layout/#Understanding_Constraints

相关问题