How do I use relative layout in Xamarin?
5 minute(s) read | Published on: Sep 20, 2021 Updated on: Jan 26, 2022 |
What are children's relatives?
As mentioned, relative offspring can be used to determine the relative size and position of offspring. In this way, in addition to choosing their size and function, it can allow them to design and create user interfaces for developing applications ( in French: concevoir et créer des interfaces utilisateur pour développer des applications )with the right size for mobile devices.
What properties can RelativeLayout define?
- XConstraint property:
XConstraint property is a related property type, and the limit can be rejected by the X position to show.
- YConstraint property:
This property is of type Constraint, a related property that indicates the position in the Y range.
- WidthConstraint property:
WidthConstraint property is of type Constraint, which can show the width limit.
- HeightConstraint property:
This property is of Constraint, related property and can show the height limit.
- BoundsConstraint property:
This property is of type BoundsConstraint, a related property that can be used to indicate the position and limitation of children relative.
BindableProperty can manage all these features.
The RelativeLayout class is a Layout -T- class that can type Children attributes as type IList -T-. Determine. It should be noted that the Children ContentProperty feature of the Layout is -T- class.
Children can be entered in the C # programming language by adding three times. The first time you enter them, you need to use phrases like -Func -Rectangle- to determine their position and size. The second time adding words like Expression -Func -double- for x, y, height, and width arguments is required. The third time, adding some optional ideas, such as Constraint for x, y, height, and width, is required.
If we want to change the position and size of children in RelativeLayout, we can use methods such as SetXConstraint, SetWidthConstraint, SetYConstraint, and SetHeightConstraint. Of course, it should be noted that the SetBoundsConstraint method can also be used.
Absolute and accurate positioning and size
RelativeLayout can specify the absolute position and size of RelativeLayout or children relative by using some fundamental values. This can be done by adding children to the Children collection of a RelativeLayout. In addition to adding some features, such as YConstraint, XConstraint, WidthConstraint, and HeightConstraint can also be specified. The following code may indicate a RelativeLayout whose children use absolute values:
In this example, the position of each BoxView object is defined using the values entered in XConstraint and YConstraint. In addition to the position, the size of each BoxView object is also determined and limited according to the values listed in the YConstraint and XConstraint sections. Label position is defined according to the values listed in the Yconstraint and XConstraint sections.
Although both the position and the size of the BoxView are defined according to the values entered in YConstraint and XConstraint, only the function of the Label is defined according to those values , and its size is not limited according to those values.
The following codes are used to determine the layout position:
In this example and the code listed above, each BoxView object is added to the RelativeLayout. In the code above, we need the phrase -Func -Rectangle- to determine the position and size of each child.
Relative and approximate position and size
RelativeLayout can specify children using values related to their timeline properties and sizes. This can be done by adding children to the Children of the RelativeLayout collection and setting the YConstraint, XConstraint, WidthConstraint, and HeightConstraint properties and setting them. In this case, the relative size of each child can be obtained.
Constraints can be fixed. ConstraintType counts can be used to indicate constraints. - RelativeToParent can indicate restrictions on parents.
- RelativeToView can also show restrictions on the view.
- Constant also indicates that the constraints are constant.
Restriction markings
It should be noted that inside the XAML file, you can mark your constraint object using ConstraintExpression markup plugins. The ConstraintExpression class can define the following properties:
- Constant:
This property is of type double, which is used to show the constant value of the Constraint.
- ElementName:
This property is of type String, which can be used to indicate the name of the source element for calculating constraints.
- Factor attribute:
Factor attribute with double type, which this attribute represents a factor that can be used to scale and calculate the constraint dimension relative to the source element. It should be noted that this feature is one by default.
- String attribute:
This attribute can indicate the name of the point on the source element.
- Type attribute:
The type attribute is of type ConstraintType and can indicate constraints.
The code below RelativeLayout shows how ConstraintExpression limits your children by marking:
In the example and the codes listed above, each BoxView is defined according to the values entered in XConstraint and YConstraint. Note that the first BoxView has Xconstraint and YConstraint properties connected to an absolute value constant. But the rest of the BoxViews are set to relative importance.
In this article, we tried to tell you tips about RelativeLayouts and even child relatives used to determine size and position. Using the codes listed above, you will see how their work and size can be changed and determined.
About our Android and iOS app development services