Previous MAUI-Layouts MAUI-BindableLayout Next

📐 Layouts in .NET MAUI – MAUI AbsoluteLayout

AbsoluteLayout in .NET MAUI

.NET MAUI’s AbsoluteLayout is a layout container that gives you precise control over the position and size of child elements, either with fixed coordinates or proportional values. It’s best used when you need exact placement, overlapping elements, or proportional scaling that other layouts don’t easily provide.

🔑 Key Features of AbsoluteLayout

Explicit Positioning: Place elements using exact X/Y coordinates relative to the layout’s top-left corner.

Proportional Positioning: Use proportional values (0–1) to size and position elements relative to the parent container’s dimensions.

Overlap Support: Unlike Grid or StackLayout, children can overlap each other freely.

Flexible Sizing: Supports both fixed units (e.g., 100px) and proportional sizing (e.g., 0.5 of width/height).

LayoutBounds & LayoutFlags: Control element placement with properties like WidthProportional, HeightProportional, XProportional, YProportional.

📘 Example Code

xml

<AbsoluteLayout>
    <!-- Fixed position and size -->
    <BoxView Color="Red"
             AbsoluteLayout.LayoutBounds="50, 50, 100, 100"
             AbsoluteLayout.LayoutFlags="None" />

    <!-- Proportional position and size -->
    <BoxView Color="Blue"
             AbsoluteLayout.LayoutBounds="0.5, 0.5, 0.3, 0.3"
             AbsoluteLayout.LayoutFlags="All" />
</AbsoluteLayout>

The red box is placed at (50,50) with a fixed size of 100x100.

The blue box is centered (0.5,0.5) and takes up 30% of the parent’s width and height.

✅ Why Choose AbsoluteLayout?

Precise Control: Ideal when UI elements must appear at exact coordinates (e.g., custom dashboards, games).

Overlapping Elements: Useful for layering graphics, annotations, or floating buttons.

Dynamic Resizing: Proportional flags make it responsive across devices without complex calculations.

📌 Common Use Cases

Custom UI Designs: Complex layouts where elements don’t follow linear stacking.

Games or Graphics Apps: Position sprites, shapes, or controls at exact coordinates.

Dashboards: Place charts, indicators, or widgets in fixed spots.

Overlays: Floating buttons, watermarks, or overlapping notifications.

Interactive Layouts: Drag-and-drop interfaces where elements move freely.

⚠️ Considerations

Not for General Layouts: Use Grid, StackLayout, or FlexLayout for standard UI since AbsoluteLayout ignores natural flow.

Maintainability: Hard-coded coordinates can be harder to adapt for different screen sizes unless proportional flags are used.

Performance: Works well for small sets of elements, but complex overlapping may require careful optimization.

In short: Choose AbsoluteLayout when you need exact placement or overlapping elements. For everyday UI, stick with Grid or FlexLayout, but for specialized designs like dashboards, games, or overlays, AbsoluteLayout is the right tool.

AbsoluteLayout vs FlexLayout in .NET MAUI

AbsoluteLayout vs FlexLayout in .NET MAUI so you can see when each shines.

⚖️ AbsoluteLayout vs FlexLayout

Feature AbsoluteLayout FlexLayout
Positioning Explicit coordinates or proportional values (LayoutBounds, LayoutFlags) Flow-based, like CSS Flexbox, with direction (row/column)
Responsiveness Needs proportional flags for scaling; otherwise fixed Naturally responsive with wrapping, alignment, grow/shrink
Overlapping Supports overlapping elements No overlap; items flow sequentially
Best For Dashboards, overlays, games, floating buttons Adaptive UIs, galleries, toolbars, tag clouds
Complexity High precision but harder to maintain across devices Easier to maintain, adapts to screen size
Use Cases - Custom graphics apps
- Drag-and-drop UIs
- Decorative overlays
- Responsive photo galleries
- Toolbars that adapt
- Wrapping content like tags or chips

✅ When to Choose Each

Choose AbsoluteLayout if you need pixel-perfect control or overlapping elements. Example: a game board where pieces must sit at exact coordinates.

Choose FlexLayout if you need fluid, responsive design that adapts to screen size. Example: a tag cloud or a photo gallery that wraps items automatically.

🎯 Quick Example Contrast

AbsoluteLayout (precise placement):

xml

<AbsoluteLayout>
    <Label Text="Overlay" 
           AbsoluteLayout.LayoutBounds="0.5,0.5,0.3,0.1"
           AbsoluteLayout.LayoutFlags="All"/>
</AbsoluteLayout>

FlexLayout (responsive wrapping):

xml

<FlexLayout Wrap="Wrap" Direction="Row" JustifyContent="Center">
    <Button Text="One"/>
    <Button Text="Two"/>
    <Button Text="Three"/>
    <Button Text="Four"/>
</FlexLayout>

👉 In short:

AbsoluteLayout = precision, overlap, fixed dashboards.

FlexLayout = responsiveness, adaptive flows, modern UI flexibility.

Back to Index
Previous MAUI-Layouts MAUI-BindableLayout Next
*