Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make layouts for several Android screen sizes?

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

like image 552
joepetrakovich Avatar asked Dec 05 '10 20:12

joepetrakovich


People also ask

How do you define dimens XML for every different screen size in Android?

You have to create a different values folder for different screens and put dimens. xml file according to densities. That will depends on your values folder which will be retreive values at most from it.


2 Answers

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.

like image 170
adamp Avatar answered Oct 03 '22 02:10

adamp


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.

like image 27
Vit Khudenko Avatar answered Oct 03 '22 02:10

Vit Khudenko