Site Loader

The Xamarin Forms Performance: AbsoluteLayout, Absolutely tricky

A brief analysis of the implications in the performance impact of AbsoluteLayout, for instance

Xamarin Forms allows you to share almost 95% of the code between platforms
Xamarin Forms allows you to share almost 95% of the code between platforms

It’s been couple month since I noticed strange behavior in my application (developed with the Xamarin Forms template for Android and iOS). At first time it moved smooth and sweet. After my customer started to demand more and more functionalities the application became at certain point more and more slow. Then why?

I started my research using the insights provided inside the same IDE (Xamarin Studio for MacOS), I moved couple options, tweaked all the compilation process, but at the same time, I had a hunch: Maybe the UI is affecting the entire package, the experience, the Karma…

Finding the problem

Moving deep in my ocean of “Xamarin Best practices documentations” online. I finally came to my very own conclusion: DO NOT BOTHER WITH ABSOLUTE LAYOUT.

Of course. Yes. According to Xamarin Official Documentation regarding this layout it describes as follows:

Because of the positioning model of AbsoluteLayout, the layout makes it relatively straightforward to position elements so that they are flush with any side of the layout, or centered. With proportional sizes and positions, elements in an AbsoluteLayout can scale automatically to any view size. For items where only the position but not the size should scale, absolute and proportional values can be mixed.

AbsoluteLayout could be used anywhere elements need to be positioned within a view and is especially useful when aligning elements to edges.

Having that preview definition I want you to focus on 3 things: Position, Scale and Size. All these depends on others elements, device working area, and so on. You may say: “RelativeLayout” also performs that way… Yes, also the RelativeLayout have its drawbacks but… I’m speaking in the name of AbsoluteLayout because I was using that for my project.

To make this story shorter, I ended up taking out all the RelativeLayout in my UI and replacing it with a better disposition of other elements with padding, margin and so on. So the performance in my application moved from very bad to very good.

Finally when referring to xamarin forms performance the information around is vast, so there is a lot of tips and tricks you can gather and analyze, for instance.

This is my very own and particular experience, so I’m not trying to look expert in the topic or illuminate your path with my wisdom, I’m just sharing my experience.

Update, please read also an updated article about performance here.


One Reply to “Xamarin Forms Performance AbsoluteLayout, Absolutely tricky”

Leave a Reply

Your email address will not be published. Required fields are marked *