Xamarin在底部形成相对布局位置stacklayout [英] Xamarin forms relative layout position stacklayout at bottom

查看:379
本文介绍了Xamarin在底部形成相对布局位置stacklayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用相对布局(仅使用xaml的Xamarin表单)将Stacklayout放置在图像顶部的底部. xaml几乎是这样的.

I would like to position a Stacklayout at the bottom on top of an image using a relative layout using Xamarin forms using xaml only. The xaml pretty much looks like this.

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

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

What X and Y constraints should my StackLayout have so that it is positioned on top of the image and at the bottom of it.Also added an image which describes the result i expect.

预期:

我确实尝试将 RelativeLayout.XConstraints RelativeLayout.YConstraints 分配给图像和stacklayout,但无法弄清楚要使用什么值来获取理想的结果.

I did try to give RelativeLayout.XConstraints and RelativeLayout.YConstraints to both the image and the stacklayout , but not able to figure out what values to use to get the desired result.

推荐答案

您可以在整个图片上放置一个StackLayout,并在其中放置另一个StackLayout,将其放置在底部:

You can have a StackLayout across whole picture and in it another StackLayout that will be placed at the bottom:

<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>

这篇关于Xamarin在底部形成相对布局位置stacklayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆