Moh*_*r K 4 xaml xamarin xamarin.forms uwp-xaml xamarin.uwp
我想使用仅使用 xaml 使用 Xamarin 表单的相对布局将 Stacklayout 放置在图像顶部的底部。xaml 看起来就像这样。
<RelativeLayout>
<Image />
<StackLayout Orientation="Horizontal">
<Label Text="Dark Mode" />
<Switch />
<Label Text="Light Mode" />
</StackLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的 StackLayout 应该有什么 X 和 Y 约束,以便它位于图像的顶部和底部。还添加了一个描述我期望的结果的图像。
我确实尝试将RelativeLayout.XConstraints和RelativeLayout.YConstraints同时提供给图像和stacklayout,但无法弄清楚使用什么值来获得所需的结果。
您可以在整个图片上使用一个 StackLayout,并在其中放置另一个位于底部的 StackLayout:
<RelativeLayout>
<Image Aspect="AspectFill"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"/>
<StackLayout
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}">
<StackLayout Orientation="Horizontal" VerticalOptions="EndAndExpand" HorizontalOptions="Center">
<Label Text="Dark Mode" />
<Switch />
<Label Text="Light Mode" />
</StackLayout>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4937 次 |
| 最近记录: |