Relative vs. Constraint Layout in Android


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.


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.

The above is a simple description about Relative vs. Constraint Layout in Android. More examples will come in the future, but make sure to experiment and make some trial and error to master Relative vs. Constraint Layout in Android.