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

How to change the position or size of a view in Relative Layout at runtime in xamarin.forms

$
0
0

What I did is I have added a label to a relative layout by setting all constraint.

Below is my code for that.

relativeLayout.Children.Add(textLabel, Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Width * 0.55; }), Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Y; }), Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Width * .45; }), Constraint.RelativeToView(innerBorderBox, (parent, sibling) => { return sibling.Height; }));

and it working perfectly.

Now I want to change that label(textLabel) X Constraint and Width Constraint dynamically. For example, from the above code X Constraint is sibling.Width * 0.55 and width is sibling.Width * .45, then need to change to X as sibling.Width * 0.55 + 10 and width is sibling.Width * .45 - 50. How to do that?

My guess is that it can be done by removing the label for the relative Layout and added again to relative layout with new constraint. But I think there will be a better solution for this.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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