Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

RelativeLayout RelativeToView "Align Bottom"

$
0
0

I'm wondering if there is a way use a relative layout to align a view to the bottom of another view from XAML? My end result looks something like a StackLayout, but I'm opting for relative layoutout to conserve on the number of nested layouts. I need to layout my views something like this:

---------------------------------
|                          |
----------------------------------
------------        ------------
|       |       |       |
-----------     ------------
------------        ------------
|            |      |       |
-----------     ------------
---------------------------------
|                          |
----------------------------------
---------------------------------
|                          |
----------------------------------

From what I've read, it is recommended to use either an absolute layout or a relative layout to conserve on the number of nested layouts. Each my individual subviews are a StackLayout, so I'd like to not nest each of them in a parent stack if possible.

It seems like the BoundsConstraint property on the relative layout would work, but I can't find any examples on how to use it. I'd like to build everything from XAML if I can.

If I approach this problem from C# I can get my desired result something like this:

    view.Children.Add(subview,
        widthConstraint: Constraint.RelativeToParent((parent) =>
        {
            return parent.Width / 2;
        }),
        xConstraint: Constraint.RelativeToParent((parent) =>
        {
            return parent.Width / 2;
        }),
        yConstraint: Constraint.RelativeToView(subview2, (parent, sibling) =>
        {
            return sibling.Y + sibling.Height;
        })
    );

but there doesn't seem to be an intuitive way to calculate the yConstraint based on 2 properties from XAML.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>