2017-06-29 21 views

回答

1

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

希望它可以帮助