28
votes

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...

3
Yes you can accomplish this in preety simple way, see my answer stackoverflow.com/a/16518557/1939564Muhammad Babar

3 Answers

14
votes

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.

3
votes

The general rule is to use Density Independent Pixels (dips) for size definitions in your layout xmls - I see you already do it. Doing so I just have the only layout for all range of devices. What needs to be splited is graphics. For that I use 3 different drawable directories - 'drawable-ldpi', 'drawable-mdpi' and 'drawable-hdpi'. This is done in order images to have the same size (let say, in millimeters) on various screen densities (assuming screen size is the same - Normal, for instance) they should be scaled as follows:

  • drawable-hdpi: 150%
  • drawable-mdpi: 100%
  • drawable-ldpi: 75%

Probably it is a bad advice. However, if you look at the Google chart of Screen Sizes and Densities you can decide to not invest your additional efforts to thorough testing for Large screens, since there are almost no such devices on the market.

1
votes

No making separate layouts is not really common practice. Only when you have images that can't be stretched is that really the recommended way.

Stuff will always look a little stretched/compressed when viewing it on devices with smaller/larger screens. That's kind of the definition of a different size screen. You should just use relative layouts and let android control the specific pixel numbers.