Tag: relativelayout

Xamarin.Forms:如何使用相对布局居中视图? `Width`和`Height`返回-1

当尝试在Xamarin.Forms中使用控件的Height和Width属性时,都返回-1,这会导致相对布局在屏幕上偏离中心。 var mainLayout = new RelativeLayout(); //Add the Switch to the center of the screen mainLayout.Children.Add(mySwitch, Constraint.RelativeToParent(parent => parent.Width / 2 – mySwitch.Width / 2), Constraint.RelativeToParent(parent => parent.Height / 2 – mySwitch.Height / 2)); //Add a Label below the switch mainLayout.Children.Add(switchLabel, Constraint.RelativeToParent(parent => parent.Width / 2 – switchLabel.Width / 2), Constraint.RelativeToView(mySwitch, (parent, view) => view.Y […]