-2

Could someone please help me out letting me know when to use the relative layout and when to use the constrain layout with example in android.

  • this link may help [Differences between ConstraintLayout and RelativeLayout](https://stackoverflow.com/questions/37321448/differences-between-constraintlayout-and-relativelayout) – AskNilesh Aug 18 '17 at 05:09

1 Answers1

1

First you need to know why ConstraintLayout is introduced later in Android SDK.

Why ConstraintLayout is introduced?

Using Relative and other layouts, we need to create a hierarchy of different views. Sometimes these hierarchy can be long with multiple nested view groups.

When Android renders layout, All the views will be rendered going to level below in nested layouts. So more levels, requires more time.

So According to Android Documentation,

ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups).

Which can take lesses time than other nested views.

What is difference between ConstraintLayout and RelativeLayout?

ConstraintLayout is similar to RelativeLayout in that all views are laid out according to relationships between sibling views and the parent layout, but it's more flexible than RelativeLayout.

When to choose which Layout? If your screen has design such that you can do using no nested RelativeLayout, Use Relative or else use Constraint.

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66