Regarding flat view heirarchyfrom the CommonsWare Community archives
At January 28, 2019, 11:52am, _shahdhaval asked:
I am seeing everyone using ConstraintLayout and by all means it is great.
But I have some doubts regarding hype of flat view hierarchy.
If I am using ConstraintLayout in my layout.xml file, then does it mean I shouldn’t use any other nested viewgroup?
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.
At January 28, 2019, 12:36pm, mmurphy replied:
RecyclerView is a
ViewGroup. 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.
At January 28, 2019, 12:51pm, _shahdhaval replied:
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.