Xamarin forms relative layout position stacklayout at bottom

元气小坏坏 提交于 2020-01-04 03:13:30

问题


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>

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.

Expected :

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.


回答1:


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>



来源:https://stackoverflow.com/questions/42919941/xamarin-forms-relative-layout-position-stacklayout-at-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!