When you build an app that will work on multiple screens,…you need to decide at runtime…how to layout the screen.…There are a couple of ways to do this.…As I'll show later, you can let Android…choose a layout by placing XML files…in resource folders that are marked…for particular screen sizes.…Or, as I'll show here, you can use a manual approach…that starts with calculating the current screen's…device-independent dimensions.…Device-independent dimensions…take into account the physical screen size,…the number of physical pixels in width and height,…and the pixel density.…

In this project named Dimensions,…I've created a utility class…that I placed in the default package.…It's named Screen Utility.…As you instantiate this class,…you pass in a reference to the current activity.…The class then does a calculation.…It starts with the physical display,…and gets the height and width in physical pixels.…These are the numbers that would match…what's on the box when you buy a cell phone…or a tablet.…But for Android design, we usually only care about…

Resume Transcript Auto-Scroll

Author

Released

8/21/2014

One of the most common issues Android developers face is market fragmentation: the variations in screen size and pixel density among the thousands of phones, tablets, and even desktop computers that run Android. The Fragments API (introduced in Android 3.0) helps you deal with this issue. This course teaches Android developers how to program with the Fragments API, and build apps that work well on a wide variety of devices. David Gassner shows how to define different fragment layouts and add them to activities with XML or Java, create layouts for different screens and use a resource alias to select the right layout at runtime, and communicate between activities and fragments. He'll also show you how to make fragments work on older versions of Android, with the support library, and use fragments to display dialogs and preference screens.