Published in


Android Dev-Tip #6

Layout comments



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:

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.

Example 1:

Assume you’ve cannot depend just on using dimens to calculate the value of View’s 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 FrameLayout.

Example 2:

See Saul’s response to the post.

If you enjoyed this post, please show your support! Clap, follow, comment, share.

This really means a lot!



The (retired) Pub(lication) for Android & Tech, focused on Development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store