How do you make layouts for several Android screen sizes?

joepetrakovich picture joepetrakovich · Dec 5, 2010 · Viewed 23.4k times · Source

I've done some research on building layouts that work for multiple screen sizes and I'm looking for some clarification.

Is it common practice to just make a separate layout file for each of the three screen sizes (small, medium, large) or can you accomplish this with an easier method?

I've been testing my projects on a large screen device, and even though I use DIPs (density independent pixels) for padding, margins, etc, it still scrunches stuff up when I view it on smaller screens. Should I be designing my projects for medium-sized screens and then just allow Android to scale it appropriately?

I'm not sure if this is a good question or not, but I am looking for what the common practice is for designing for multiple screen sizes. What do you do?

Edit: In addition to this, for example, let's say I have a button that is 40dip above the bottom of the screen, should I literally write 40dip, or should I be using some sort of pixel math like 40 * screenWidth / blahblah or something so that it scales depending on the screen size the user has? I have limited experience with UIs...

Answer

adamp picture adamp · Dec 5, 2010

There are two axes to consider when it comes to screen size: physical size and density. Density is handled by providing measurements in dips and scaled resources as appropriate. But density does not always imply size or vice versa. See http://developer.android.com/guide/practices/screens_support.html for some further info on the mechanics.

It is not common or recommended to have different layouts based on each screen resolution you support, but it is entirely reasonable to design different layouts for different size classes (small, medium, large). Different sized screens might benefit from adding, removing, or repositioning certain navigation elements depending on the app.

Within a certain size class you should make sure that your layouts tolerate variances in exact screen resolution. As Falmarri suggested, use relative layouts, weights, and the other tools available to let your layout stretch gracefully.