简体   繁体   中英

in Xamarin How to change frame of superview when constraints are added to subviews programatically?

TopView : Superview, Subviews in topview : confirmImage,confirmationInfoView, visitLabelContainer, noteTextLabel, dashboardButton.

contentContainer : Superview of TopView

Constrains added to topview :

topView.AtLeftOf(contentContainer),
topView.AtRightOf(contentContainer),
topView.AtTopOf(contentContainer),
topView.Height().EqualTo(444),

Constraints Added to subview of topView :

topView.AddConstraints(

confirmImage.WithSameCenterX(topView),
confirmImage.AtTopOf(topView, 27),
confirmImage.Width().EqualTo(94),
confirmImage.Height().EqualTo(94),

confirmationInfoView.Below(confirmImage, 28),
confirmationInfoView.WithSameCenterX(topView),
confirmationInfoView.Width().EqualTo(284),
confirmationInfoView.Height().EqualTo(116),

visitLabelContainer.Below(confirmationInfoView, 3),
visitLabelContainer.WithSameCenterX(topView),
visitLabelContainer.Width().EqualTo(138),
visitLabelContainer.Height().EqualTo(19),

noteTextLabel.AtBottomOf(topView, 29),
noteTextLabel.WithSameCenterX(topView),
noteTextLabel.Width().EqualTo(343),
noteTextLabel.Height().EqualTo(36),

dashboardButton.AtBottomOf(topView, 87),
dashboardButton.WithSameCenterX(topView),
dashboardButton.Width().EqualTo(347),
dashboardButton.Height().EqualTo(44)

);

If i change frame height of topview it doesn't change anything. If i change bounds height of topview it changes frame 'y' to negative. (half of a height).

Can anyone please suggest me how to change frame in xamarin when constrains are enabled.

Thanks in advance.

Since you have used autolayout to place your control, you should modify the height constraint to change the height of topview:

foreach (var constraint in contentContainer.Constraints)
{
    if (constraint.FirstItem == topView && constraint.FirstAttribute == NSLayoutAttribute.Height)
    {
        constraint.Constant += 174;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM