Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin forms relative layout position stacklayout at bottom

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

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.

like image 399
Mohammed Aamir K Avatar asked Aug 30 '25 16:08

Mohammed Aamir K


1 Answers

You can have a StackLayout across the whole picture and inside 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>
like image 70
Uros Avatar answered Sep 02 '25 15:09

Uros