How to Make Layouts for Several Android Screen Sizes

How do you make layouts for several Android screen sizes?

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.

Android layouts for different screen sizes

The answer is already given by user5594218 but looks like you are still unclear. (maybe you are beginner)

So, here is the step by step guideline

Solution 1: (short and simple)

  1. Navigate to app > src > main > res

  2. Duplicate layout directory by copying and pasting

  3. Rename duplicated Directories e.g layout-sw300dp

Solution 2: (bit lengthy)

  1. Create new resource directory: res > New > Android resource directory

Create new resource directory


  1. Select Resource Type as layout

  2. Add sw<N>dp in Directory name e.g layout-sw300dp and Hit OK

Sample Image


  1. Navigate to app > src > main > res

  2. Copy layouts XML file inside new directory

    //repeat process for other qualifiers

List of Qualifiers to support all screens:

  • layout-sw300dp
  • layout-sw330dp
  • layout-sw480dp
  • layout-sw600dp
  • layout-sw720dp

Testing:

This is how it gonna look like, if you did it right.
Sample Image

For more detail and examples, check: Android Application Development All-in-One For Dummies

How to set android layout to support all screen sizes?

Please go through the following links. These might help you:

Supporting Different Screen Sizes

Supporting Multiple Screens

Supporting Different Densities

Supporting Tablets and Handsets

AFAIK, the only way to support all screens is by doing that folder bifurcation. Every XML file goes up to a few kilo bytes. So, size shouldn't be too much of an issue as such.

Design for Different Screen Sizes Android

There is no need to create different layout for different screen resolutions..
Just put your images in folder named :

for resolution - 320*480
=========================================
Folder Name : drawable - mdpi

for resolution - 480*800
=========================================
Folder Name : drawable-hdpi

for resolution - 540*960
=========================================
Folder Name : drawable-sw360dp-hdpi

for resolution - 720*1280
=========================================
Folder Name : drawable-sw360dp-xhdpi

for resolution - 768*1280
=========================================
Folder Name : drawable-sw360dp-notlong-hdpi

How to create a layout folder for a smaller screen size?

I have put the layouts for the smallest screen size in the base layout folder and created secondary layout folders with smallest width qualifiers to support larger screen sizes.

That is the correct approach, both for your original scenario and your new one. More specifically, your "secondary layout folders" would only contain layouts where you need to change something based on that larger screen size. Everything else would only be in res/layout/.

I was hoping to find a "maximum width" qualifier but it doesn't seem to exist.

Correct.

If I had to update every layout for the smaller screen size then I would simply move my larger screen layouts to a folder with a smallest width qualifier but I only need to update 5 of the 50 or so layouts for the smaller screen size.

Sorry, but you do not really have a choice. res/layout/ needs to hold one copy of every layout, set up for the smallest screen size that you are going to support. You override for larger screen sizes for the specific layouts that need to change for those larger screen sizes.

There is no means of saying that res/layout/ is in the middle of the screen size range, and you want to override for smaller sizes as well as for larger sizes.

android layout at different screen sizes

Yes there is a way.

First off all you should use DP or SP unit instead of PX. The DP unit have in consideration the size of the screen and the screen resolution. You can see more in here:

What is the difference between "px", "dp", "dip" and "sp" on Android?

Also you can create a folder in res and add different sizes for different devices.

Example:

You already have the folder 'values' with the file 'dimens.xml' in there you can add margins and sizes variables.

If you create the folder 'values-large' and copie the file 'dimens.xml', you can change the sizes of the variables and maintain the name.

In devices 'large' it will load different values from the rest of the devices.

You can see all documentation in here: http://developer.android.com/guide/practices/screens_support.html

Hope it helps you.



Related Topics



Leave a reply



Submit