Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to specify multiple LayoutFlags in XAML Xamarin?

I Have a label set to relative positioning and auto size as shown below

<Style TargetType="Label">
    <Setter Property="BackgroundColor" Value="Transparent" />
    //Something like below?            
    <Setter Property="AbsoluteLayout.LayoutFlags" Value="PositionProportional | SizeProportional" />
</Style>

....

<Label Text="0" AbsoluteLayout.LayoutBounds="0.5, 0.00499999999999998, AutoSize, AutoSize"/>

Is there a way to specify multiple LayoutFlags in XAML?

As I run the code on devices with higher resolution the relative position of the label is correct but the size (font) of the label does not increase, although it is set to AutoSize. I figured I also needed to specify a LayoutFlag for the Label that is SizeProportional as well as PositionProportional. But how to do it in XAML? Currently the fonts don't resize when the device is rotated to landscape orientation.

like image 840
Anna Avatar asked Feb 20 '17 20:02

Anna


People also ask

How do I use absolute layout in xamarin?

An AbsoluteLayout can position and size children using proportional values. This is achieved by adding children to the Children collection of the AbsoluteLayout , and by setting the AbsoluteLayout. LayoutBounds attached property on each child to proportional position and/or size values in the range 0-1.

Which layout control in xamarin forms displays information in columns and rows?

Grid. A Grid is used for displaying elements in rows and columns, which can have proportional or absolute sizes.


1 Answers

As you can read here : AbsoluteLayout on Xamarin Documentation

Flags are also specified in the declaration of views in the layout using the AbsoluteLayout.LayoutFlags property. Note that flags can be combined in XAML using a comma-separated list.

So in your case, there is no point since you want to use the All value (using both Positionning and Sizing proportionnaly). But I had to use something like this and it works just fine :

<StackLayout AbsoluteLayout.LayoutBounds="0,1,1,100"
                 AbsoluteLayout.LayoutFlags="XProportional,YProportional,WidthProportional">
</StackLayout>

Hope it will help people like who googled it and found this post :)

like image 182
Valentin Helmer Avatar answered Oct 17 '22 14:10

Valentin Helmer