If some part of your layout xml is not clear right off the bat (e.g. the existence of seemingly unnecessary View or weird parameter), mark your intentions with a comment (in this xml).
You can treat this tip as a paraphrase of Explanation of Intent section (chapter: Comments) from the:
Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin)
Even bad code can function. But if code isn't clean, it can bring a development organization to its knees. Every year…
With the specifics of Android SDK this tip gets a special meaning if you consider layout xmls.
The things you can set in the layout xml can sometimes be just not enough for your case. E.g. you might need to introduce a seemingly unnecessary
View to make your
layout work as expected or tweak some parameters of your
Views from code to make them look exactly right.
Adding a simple comment (in the xml) to a particular
View is a simple solution that can be priceless for the future You or some other fellow developer that will have to work with your code. It can save hours of trying to understand a seemingly broken layout by just reading the tip.
Assume you’ve cannot depend just on using
dimens to calculate the value of
padding. You need to utilise few lines of your code to do that.
Add a simple comment to your layout xml, so when you get back to this part of your app, you don’t need to spend any time figuring out the source of the
padding in this