A (175)

(Tuis.) #1

78 CHAPTER 3: An Introduction to the Android Application Development Platform


   dimension resources (dimensions and units of value)
 bool resources (boolean true or false values)
 integer resources (numeric constants)
 array resources (collections of data values)

You can also provide something called alternative resources in the application project folder
hierarchy. These alternate resource folders provide support for a wide array of device types or
physical hardware specifications by grouping new media assets, user interface designs, and style
and theme definitions into specifically named alternate resource folders. The /res/values-sw600dp/
folder in Figure 3-9 is an example of an alternate resource folder, and holds assets that are specific
to your application design for 600-pixel or greater screen dimensions. We’ll be covering alternate
resources as they relate to UI layout design a bit later on in this book.


At runtime, which we learned all about in the first part of this chapter, Android OS uses an
appropriate resource, based on the device’s hardware specifications. As an example, if you want to
provide different UI design layouts that morph, or change based on the physical screen size, shape,
or orientation (portrait or landscape), you can define different UI layout designs using different layout
folder names, such as /res/layout-land for a landscape-specific UI layout design, or /res/layout-port
for a portrait-specific UI layout design. We will be looking at all of this in greater detail in a future
chapter on UI design principles and techniques.


As another example, you could define different string (a collection or array of text characters) values,
which would be evaluated at runtime based on the language setting on the end-user’s Android
device. As you can see, there is a reason for the way Android organizes resources, and one of the
major reasons is so that developers can create alternate resources (alternate resource folders) that
can be accessed at runtime based on Android device characteristics. As this book progresses, I will
show you how to reference and access these external resources from within your Java code and
XML mark-up. We will get into how to set up alternate resource folders in the chapters covering user
interface design, themes, and styles. Let’s look at drawables next!


Android Drawable: Assets that Draw to a Screen


A “drawable” in Android is aptly named, as it is anything that can be drawn to the display screen. As
you can see in Figure 3-9, Eclipse ADT created five /res/drawable subfolders, named drawable-ldpi,
drawable-mdpi, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi for your use. It is
important to note that as of Android 4.2, there’s also an xxxhdpi resolution density that has been
added to Android to accommodate the new Ultra High Definition (UHD) (or Ultra High Density, in
this case) displays, such as those found on 4K TVs, which have a 4096 by 2160 resolution, or the
screen on the new Samsung Galaxy S5, which has a 2560 by 1440 pixel resolution screen. From
smartwatch (ldpi) to 4K TV (xxxhdpi), Android has a density constant to fit any device!


You will be learning all about pixels and resolutions in Chapter 9, covering graphic design, but to
give you an overview here of what these different DPI levels are for Android’s screen resolution
density constants, I have put all of the density constant data together here, in Table 3-2, for those of
you who are already “pixel savvy.”

Free download pdf