Regarding flat view heirarchy



I am seeing everyone using ConstraintLayout and by all means it is great.
But I have some doubts regarding hype of flat view hierarchy.

  1. If I am using ConstraintLayout in my layout.xml file, then does it mean I shouldn’t use any other nested viewgroup?

  2. For developing some UI I find my self using LinearLayout inside ConstaintLayout or ConstraintLayout inside ConstraintLayout. So is it considered bad practice?

I dont’t understand the situation as there are no examples available for complex UI using ConstraintLayout on internet to examine.

Please provide some guidance regarding this and please tell us best practices or things to keep in mind while using ConstraintLayout.

Thank you.


Well, RecyclerView is a ViewGroup. :slight_smile: If you mean that you should not use any other nested layout… use one if you have a very specific need for it:

  • You need to have a separate background behind some group of widgets
  • You need some capability that cannot be achieved by ConstraintLayout (e.g., perhaps some features of TableLayout) for some group of widgets

In general, you should not need nested layouts, but there will be cases where they are unavoidable.

If you need those for something other than positioning — such as having a background — what you have may be fine. However, I have not encountered any scenario in which I needed nested ConstraintLayouts, or a LinearLayout in a ConstraintLayout, purely for positioning. I cannot rule out the possibility that there is such a scenario, but I suspect that it is uncommon.


Thank you for clearing things for me.
I will try some layouts on my own and if there is any specific situations arises, I will ask for more guidance.

Thank you.