Xamarin Forms - AbsoluteLayout - How Positions Work

I work with Xamarin.Forms with AbsoluteLayout, however I'm not sure I will understand how element positioning works.

I work with Proportional values, so if I put an element in AbsoluteLayout.LayoutBounds="1, 0.05, 0.15, 0.1"where each value is Proportional (therefore the "all" flags AbsoluteLayout.LayoutFlags="All")

It will be placed at the top / right of the screen. It does not take up a bit of space outside however. So what does that mean? Each element moves to the screen if they go outside?

enter image description here

But now another question arises: when you place an element, what is the X / Y position based on? Is there a center or another point?

enter image description here

In this example, I tried with 0.15, but the rendering was a bit strange, so I set it to 0, and then the rendering corresponded to what I want.

" , ". , , , , , . , ..

, , . X/Y .

!

+8
5

AbsoluteLayoutFlag.All Rectangle bounds :

  • x (.. ),
  • y ( - ),
  • width -
  • height -

- , . x y , "" "". , , x y:

x = /(1 - )
y = /(1 - )

+15
<AbsoluteLayout BackgroundColor="Yellow">
<BoxView
    Color="Red"
    AbsoluteLayout.LayoutBounds="1.0, 1.0, 0.5, 0.5"
    AbsoluteLayout.LayoutFlags="All" />

<BoxView
    Color="Green"
    WidthRequest="50"
    HeightRequest="50"
    AbsoluteLayout.LayoutBounds="0.1, 0.1, AutoSize, AutoSize"
    AbsoluteLayout.LayoutFlags="PositionProportional" />

<BoxView
    Color="Blue"
    AbsoluteLayout.LayoutBounds="0.25, 0.25, 0.5, 0.5"
    AbsoluteLayout.LayoutFlags="All" />
</AbsoluteLayout>

enter image description here

AbsoluteLayout,

,

: X Y - View. . , 1.0, 1.0 , , , 100% 2.0 ( ). AbsoluteLayout AbsoluteLayout.

:

X Y - View, . 100% Width - 1.0.

+6

X && Y -

+1

, AbsoluteLayoutFlag.All, , X, , . , X = 10%, 10% :

= 0,1 20%. 90% , 10% - .

= 0,5 20%. 10% 10% .

X

(Ax, Ay, Wx, Wy):

W -

Ax - X ( )

X1 - X (X = 0)

X2 - x (X = 0)

5

Ax = 0:

X1 = 0 X2 = Wx

Ax = 1:

X2 = 1 X1 = (1 - Wx)

Ax = 0,5

1 = - (0,5) ()

X2 = Ax + (0,5) ()

0 <Ax <0,5

X1 = Ax - (Ax) (Wx)

X2 = Ax + (1 - Ax) (Wx)

0,5 < <1

X1 = Ax - (Ax) (Wx)

X2 = Ax + (1-Ax) (Wx)

0

nuget AbsoluteLayout, , .

Install the package SmartMachines.AbsoluteLayout, add a namespace xmlns:sm="clr-namespace:SmartMachines;assembly=AbsoluteLayout"and you get exactly the same AbsoluteLayout as your own Xamarin, but with the expected proportional alignment behavior.

Hope this saves other people a few hours searching and debugging.

0
source

All Articles