我有一个设计要求,如图像(虽然这是简化版) .
我需要按钮的最终x坐标和要对齐的图像,按钮需要向左扩展,具体取决于绑定的文本 .
我做了什么:
<RelativeLayout Padding="0,0,0,0" Margin="0,0,0,0"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand">
//other children
<Image Source="circle.png"
Aspect="AspectFit"
x:Name="circleImg"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width, Factor=0.48, Constant=0}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width, Factor=0.811, Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width, Factor=0.1593, Constant = 0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width, Factor=0.1593, Constant = 0}">
</Image>
<Button
Text="{Binding ButtonText}"
TextColor="White"
BorderColor="Transparent"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height, Factor=0.0, Constant=0}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView,
ElementName=circleImg, Property=X, Factor=1, Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width, Factor=0.1593, Constant = 0}"/>
//other children
</RelativeLayout>
这给了我一个按钮,开始与图像的起始位置对齐,宽度等于图像 . 但是,如果绑定文本很长,则文本会被截断 . 我试过 VerticalOptions="EndAndExpand"
,但它不起作用 .
有没有办法可以指定按钮的结束x坐标,而不是它的开始,并使其向左展开?