android – dimen.xml or dimens.xml?-ThrowExceptions

Exception or error:

I usually store dimensions in dimen.xml file. However, IntelliJ IDEA’s intellisense places dimensions into file dimens.xml.

Now, what if I place dimensions into the file dimens.xml, how will Eclipse handle this?

I see that docs allow both files to be used. Which one should be used if the project will be used by both Eclipse and IDEA users?

How to solve:

It doesn’t really matter what you name the file itself, however there are recommendations. From the docs (on res/values):

Because each resource is defined with its own XML element, you can
name the file whatever you want and place different resource types in
one file. However, for clarity, you might want to place unique
resource types in different files. For example, here are some filename
for resources you can create in this directory:

  • arrays.xml for resource arrays (typed arrays).
  • colors.xml for color values
  • dimens.xml for dimension values.
  • strings.xml for string values.
  • styles.xml for styles.

Edit: For clarity, the important part is that you use the appropriate element (<dimen> in this case) inside a <resource> tag in your file. This is how android knows it’s a dimension resource.

    <dimen name="my_dimen">10dip</dimen>

Leave a Reply

Your email address will not be published. Required fields are marked *