Last active
August 29, 2015 14:02
-
-
Save jwill/6e10a96fb5cfde9dd3a3 to your computer and use it in GitHub Desktop.
t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It looks like we’re about to start implementing our tablet design, so now’s a great time to introduce you to the Android resource framework. | |
All externalized Android resources -- everything from strings, to layouts, to drawables, and animations are stored within your projects [draw] res folder. | |
You’ve already been putting your strings in the strings xml file stored in the [draw] values folder, and your layouts in the [draw] layout folder. | |
You reference your resources using the @ notation within your XML or in code, then at run time Android inserts the appropriate resource. | |
So far so good -- and here’s where things get interesting. | |
Android allows you to create alternative versions of every resource, by placing them into folders with different qualifiers - separated with a hyphen - based on anything from [draw] language and / or dialect, to... | |
[draw] whether the device is docked, | |
[draw] the type of touch screen, | |
[draw] the pixel density of the display, | |
[draw] the screen orientation, and most importantly for responsive design... | |
[draw] the smallest available screen width. | |
At runtime, Android will check the current device configuration, language, screen size, and pixel density and load the right layouts, strings, and drawables. | |
You can chain these qualifiers together, for example to create a different layout for German language users to account for their long words -- or more typically, for a combination of screen size and device configuration. | |
Keep in mind that many of these values can change at runtime -- the most common change being orientation. It’s for this reason that Android activities are destroyed and recreated whenever the device configuration changes -- as the layout, and all the resources within it, could be completely different based on a simple rotation. | |
It’s good practice to localize your apps and provide translated strings for all users -- a task made easier thanks to the Google Play publisher site that can offer that service. | |
It’s also a good idea to provide different drawables at the appropriate pixel density, so you get nice crisp images on every device. | |
When it comes to providing alternative layouts, Android has gone through a few alternative models -- starting with screen “buckets” of small, normal, large, and extra large -- but since Android 3.2 the new smallest width qualifier has given us more fine grained control over our layouts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment