I have the habit of using XML resources for everything… I mean, every single numeric value, I put it in dimens.xml, for instance. But is this wise?
Example:
I have this layout for ad banners which I include in other layouts. The banner view has a minHeight associated of 50dp. This specific 50dp won’t be used anywhere else, it is only relevant for the banner minHeight. I might use 50dp somewhere else but in a completely different context. They are both 50dp but they have nothing in common besides the value itself.
My question is, should I put the banner 50dp in the dimens.xml and use the appropriate reference or should I just 50dp directly since I won’t be repeating this banner minHeight value anywhere?
Is there any kind of convention on this for Android projects?
I think it is a great practice to use. In this case, you could probably get away with using the numerical value, but doing it the way you have, using the XML, creates situation where if you ever need to update your code, you only have to go to one spot. It may be one now, but if you ever grow your project, it might be 2, or 3 and so on. Like I said, I think it is a great practice and a great habit to be in; but, you don’t have to.
It’s your call.