The Android tablet computers introduced in 2010 were essentially just larger phones, and most lacked direct access to the Android market. At the start of 2011, it seems the Android tablet is coming into its own. The Motorola Xoom was given the Best of Show award at CES, and multiple other Android tablets were also unveiled. In addition, Android 3.0 (Honeycomb) is planned to launch in the first half of 2011, and it is especially tuned for tablets [ 1 ].
Given the backward compatibility of Android, existing apps will most likely still work with tablets, but anyone who has tried an iPhone app on an iPad will realize it is a much better experience when the app is catered to the larger screen.
In advance of the Honeycomb release, what are important aspects that an Android developer should consider in catering an app to tablets?
Utilize the Screen Size
Using the full screen is important to the tablet experience. In general, the default layouts in res/layout/ should scale fine as long as:
- For a generic layout measure, use wrap_content or fill_parent when possible.
- For a specific layout measure, use dp for device-independent dimension and scale.
For more direct control, use an alternate resource directory. For example, the Motorola Xoom has a pixel resolution of 1280x800 on a 10.1 inch display, which means that
- Any screen seven inches or larger is classified as an extra-large screen in Android, specified as –xlarge.
- The ratio of pixel width to height, 1.6, is considered a wide screen, specified as –long.
- The dots per inch is roughly 150dpi, or a –mdpi resource.
Every app has a default resources directory for images and strings or other values:
However, if these defaults were already tuned for phone screens, create an additional alternate directory for tablets such as res/layout-xlarge-long-mdpi/ or res/drawable-xlarge/.
Also, make sure the API level specified is 4 or above in the AndroidManifest.xml; otherwise, it is important to specify the supports-screens element so that the app is displayed on newer devices.
Testing a screen size can be done using the emulator. Create a new Android Virtual Device (AVD) and specify the pixel size and density. This can be done in Eclipse by choosing Window à Android SDK and AVD Manager à New, which provides the first menu shown in Figure 1.
Other items can optionally be specified such as Keyboard support. After creating the AVD, hit the Start button and specify the size as it would appear on the development machine (to ensure the emulator pop-up is not larger than the available screen). Finally, edit Run Configurations for a specific project to use the newly created tablet AVD.
Figure 1 Two menus in Eclipse to specify a tablet Android Virtual Device in order to test layout and functionality