20.08.2016 Views

Professional Android 4 Application Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

434 x CHAPTER 11 ADVANCED USER EXPERIENCE<br />

FIGURE 11-2<br />

NinePatch Drawables<br />

NinePatch (or stretchable) images are PNG files that mark the parts of an image that can be<br />

stretched. They’re stored in your res/drawable folders with names ending in .9.png extensions.<br />

res/drawable/stretchable_background.9.png<br />

NinePatches use a one-pixel border to define the area of the image that can be stretched if the image<br />

is enlarged. This makes them particularly useful for creating backgrounds for Views or Activities<br />

that may have a variable size.<br />

To create a NinePatch, draw single-pixel black lines that represent<br />

stretchable areas along the left and top borders of your image, as<br />

shown in Figure 11-3.<br />

The unmarked sections won’t be resized, and the relative size of each<br />

of the marked sections remains the same as the image size changes, as<br />

shown in Figure 11-4.<br />

To simplify the process to create NinePatch images for your application,<br />

the <strong>Android</strong> SDK includes a WYSIWIG draw9patch tool in the<br />

/tools folder.<br />

Creating Optimized, Adaptive,<br />

and Dynamic Designs<br />

FIGURE 11-3<br />

When designing your UI, it’s important to ensure that not only are<br />

FIGURE 11-4<br />

your assets and layouts scalable, but also that they are optimized for<br />

a variety of different device types and screen sizes. A layout that looks<br />

great on a smartphone may suffer from excessive whitespace or line lengths on a tablet.<br />

Conversely, a layout optimized for a tablet device may appear cramped on a smartphone.<br />

It’s good practice to build optimized layouts for several different screen sizes that take advantage of<br />

their relative size and aspect ratio. The specific techniques used to design such UIs are beyond the<br />

scope of this book, but they are covered in detail at the <strong>Android</strong> Training site: http://developer<br />

.android.com/training/design-navigation/index.html.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!