Criteria for choosing layouts in xml

I’m new to xml layout. I am confused which layout to choose, LinearLayout, RelativeLayout or ConstraintLayout, or others. In what scenarios should I use each?

>Solution :

  • Linear layout – when you need to group few elements horizontally or vertically. Typically used as a nested layout of the relative layout.
  • Relative layout – when you need to layout multiple nested layout groups, you can align items center, left, top, etc. Typically used as root view layout in the past.
  • Constraint layout – this layout allow to group flat hierarchy of elements, with constraints you can combine the power of linear and relative layout and your layout will be much readable.

Leave a Reply