Posted on

Android RelativeLayout vs ConstraintLayout

android relativelayout vs constraintlayout

If you started Android development just recently you might not even know about RelativeLayout, because BasicActivity template goes with ConstraintLayout, but before there was a RelativeLayout. Let’s compare those two

What’s RelativeLayout?

RelativeLayout is a way to implement¬†complex layouts with flat (one level of nesting) design. By its design, it’s overlaying items, unlike LinearLayout that never does that

Its name says by itself, RelativeLayout is great at positioning items relative to other. Let’s say you have undetermined view width and you want to put an item to the right of it and to the bottom of it at the same time. You can do that with LinearLayout, but it would take two nested, with RelativeLayout it got way cleaner

What’s ConstraintLayout

The core is RelativeLayout where items can overlay. But what makes ConstraintLayout great is it can replace all the other layouts: Frame, Relative, Linear. Yes, there are many other layouts, but those are wrappers

What I like about ConstraintLayout is that it’s really great at using in Design mode, before I didn’t like it at all. Mostly because of poor performance of my mediocre hardware (for Android Studio) and common rendering bugs

ConstraintLayout attributes actually are so long and ugly that it’s better using it Design mode. It can manipulate position and dimensions (unlike RelativeLayout) of views. Remember, that parameters starting with layout_¬†are meant for wrapping layout. View itself doesn’t handle those

So you can use your favorite weight from LinearLayout in ConstraintLayout by constraint chains, alight left/right/top/bottom of from RelativeLayout, overlay items like in simple FrameLayout

I think nobody uses GridLayout, it’s way too frustrating, always preferred nested LinearLayout, with ConstraintLayout you can do that easily

ConstraintLayout cons

Although it’s great, design mode still isn’t as perfect as XML. It gets cluttered easy, you need to zoom in on views and it forces you to have just ConstraintLayout, if you try to add some nested layout – you’d regret it


Definitely, check every feature ConstraintLayout got. I have several posts about it here. And after it, I challenge you to use in XML. Tell me how it feels. Also tell me if you’re still using RelativeLayout or not


Don’t forget to subscribe, follow me on Twitter, Facebook, G+ to get notified about the latest posts!

  • Andres Garcia

    Yep, ConstraintLayout all the way !!!
    As far as I’m concerned, I rarely use the other Layouts anymore. Let’s say that 90% of my Layouts are ConstraintLayout