Ich bin neu in Xamarin Formen (Swift ist meine Stärke). Damit meine App über alle Bildschirmgrößen hinweg funktioniert, verwende ich ein relatives Layout. Das einzige Problem ist, ich kann nur herausfinden, wie Sie die Breite und Höhe einstellen.Xamarin bildet relative Layoutbeschränkungen oben und unten
Was ich tun möchte, ist die oberen und unteren Randbedingungen festlegen.
Dies ist, was ich in schnellen tun können:
lassen Redbox = UIView() redBox.translatesAutoresizingMaskIntoConstraints = false redBox.backgroundColor = .red
let blueBox = UIView()
blueBox.translatesAutoresizingMaskIntoConstraints = false
blueBox.backgroundColor = .blue
view.addSubview(redBox)
view.addSubview(blueBox)
redBox.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
redBox.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
redBox.heightAnchor.constraint(equalToConstant: 150).isActive = true
blueBox.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
blueBox.topAnchor.constraint(equalTo: redBox.bottomAnchor).isActive = true
blueBox.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
Die im folgende Bild ergibt:
Wie würde ich thi erreichen s in Xamarin Formen? Ich kann nur herausfinden, wie man Width und Height Constraints macht. Ich möchte es auch programmatisch statt XAML oder Drag & Drop machen.
var layout = new RelativeLayout();
Content = layout;
var aquaBox = new BoxView()
{
Color = Color.Aqua
};
var silverBox = new BoxView
{
Color = Color.Silver
};
aquaBox.HeightRequest = 150;
layout.Children.Add(aquaBox,
widthConstraint: Constraint.RelativeToParent(parent => parent.Width)
);
layout.Children.Add(silverBox,
yConstraint: Constraint.RelativeToView(aquaBox, (RelativeLayout, element) => element.Height)
);
XAML:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Test" x:Class="Test.TestPage">
</ContentPage>
Das Ergebnis dieses Codes ist:
Hier ist der C# Xamarin Formen Code, ich habe herausgefunden
Was C# Xamarin Formularcode ist erforderlich, um die gleiche Ansicht wie bei swift zu erhalten?
Hinweis: Ich möchte Xamarin Formularcode und nicht separaten Code für Android, Windows und iOS.