Each resource must be uniquely named Understanding How Resources Are Resolved

Each resource must be uniquely named understanding

This preview shows page 13 - 19 out of 112 pages.

Each resource must be uniquely named.
Image of page 13

Subscribe to view the full document.

Understanding How Resources Are Resolved The Android platform has a very robust mechanism for loading the appropriate resources at runtime. You can organize Android project resources based on more than a dozen different criteria. Resources stored at the directory hierarchy are considered default resources . Under certain conditions, you can also supply special versions of your resources to load instead of the defaults. These specialized resources are called alternative resources . Some common reasons that developers use alternative resources: Internationalization Localization Accommodating different device screens and orientations
Image of page 14
Understanding How Resources Are Resolved (Cont’d) Default and alternative resources are best illustrated by example. Let’s presume that we have a simple application with string, graphics, and layout resources. In this application, the resources are stored in the top-level resource directories. For example: res/values/strings.xml res/drawable/mylogo.png res/layout/main.xml No matter what Android device you run this application on, the same resource data is loaded and used. This application uses only default resources. But what if we want our application to use different graphics sizes based on the screen density? We could use alternative resources to do this.
Image of page 15

Subscribe to view the full document.

Understanding How Resources Are Resolved (Cont’d) Low-density screens res/drawable-ldpi/mylogo.png Medium-density screens res/drawable-mdpi/mylogo.png High-density screens res/drawable-hdpi/mylogo.png Extra-high-density screens res/drawable-xhdpi/mylogo.png Extra-extra-high-density screens res/drawable-xxhdpi/mylogo.png Layout loaded in portrait mode res/layout-port/main.xml Layout loaded in landscape mode res/layout-land/main.xml
Image of page 16