Android Tip: Avoid Hard-coded Sizes

I often run across Android layouts which use hard-coded margins, padding, and font sizes, like this:

android-layout-hardcoded-sizes

Doing this often leads to inconsistency. Different layouts end up hard-coding different font sizes and margins, making the app appear less polished.

To avoid this, I recommend defining the sizes in values.xml like this:

android-layout-values

And then referring to these sizes in your layouts like this:

android-layout-declared-sizes

If every layout uses only the sizes defined in values.xml, then not only will your app appear more consistent but it will also make it much easier to adjust sizes application-wide.