【问题标题】:Xamarin forms relative layout position stacklayout at bottomXamarin 在底部形成相对布局位置 stacklayout
【发布时间】:2017-08-12 16:41:47
【问题描述】:

我想使用仅使用 xaml 的 Xamarin 表单使用相对布局将 Stacklayout 放置在图像顶部的底部。 xaml 看起来很像这样。

<RelativeLayout>
    <Image />
    <StackLayout Orientation="Horizontal">
        <Label Text="Dark Mode" />
        <Switch />
        <Label Text="Light Mode" />
    </StackLayout>
</RelativeLayout>

我的 StackLayout 应该有什么 X 和 Y 约束,以便它位于图像的顶部和底部。还添加了一个描述我期望结果的图像。

预期:

我确实尝试将 RelativeLayout.XConstraintsRelativeLayout.YConstraints 赋予图像和 stacklayout ,但无法弄清楚使用什么值来获取想要的结果。

【问题讨论】:

  • 你可以用Grid代替RelativeLayout
  • @EgorGromadskiy 我确实已经尝试过这种方法,但是即使 Aspect 设置为 AspectFill,我的图像也不会在网格内拉伸。

标签: xaml xamarin xamarin.forms uwp-xaml xamarin.uwp


【解决方案1】:

您可以在整个图片中使用 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>

【讨论】:

  • 这不是一个很好的方法,因为您会丢失诸如地图上的滚动视图之类的事件。
猜你喜欢
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-15
  • 2015-10-04
  • 2020-01-21
  • 2021-02-09
相关资源
最近更新 更多