Android and the Various Resolutions – Guide for Developers

Hello viewer, You can now have our Tutorial Lessons in your android mobile device and read it offline.
Download kotlin Programming APP on PlayStore
Download Website SEO Lessons APP on PlayStore

Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - multiscreensupportAndroid, to iOS difference, is mounted on many devices with different resolutions. To get an app with many downloads are necessary, indeed obligatory, adapting graphics for all resolutions. There are, in fact, the market many devices with different resolutions and dpi; It must consider that an app can be run either on a smartphone than on a tablet and that in itself should clarify the situation a little. Do not be

 

alarmed, there’s always google that gives us a hand, thanks to its API (API level 4).

Topic: Android and the Various Resolutions – Guide for Developers

Terms and main concepts

Screen Size

The physical size, measured as screen diagonal. For simplicity Android resolutions divides into four sections: small, normal, large, xlarge.

Screen Density

It represents the amount of pixels in a specific area of the screen, usually referred to as dpi or dp. For example, a low-density screen, and then with a few dp,  will certainly have fewer pixels than a high-density screen.

Orientation

The screen orientation from the end user perspective. This can be horizontal or vertical. So you have to be aware that the user can change the orientation of the phone when he wants, so the graphics will have to adapt.

Density-independent pixels (dp)

A dp or dpi is equivalent to a physical pixel on a 160 dpi screen, which is the core density assumed by the system of a screen with a resolution of “medium”. At runtime. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). You should always use dp units when defining the application’s user interface to ensure proper user interface display on screens with different densities.

Topic: Android and the Various Resolutions – Guid for Developers

supported Screens

As anticipated, to manage the layouts for all screens, add folders to the four major resolutions:

res / layout / my_layout.xml     # layout for normal screen size ( “default”)
res / layout-small / my_layout.xml     # layout for small screen size res / layout-large / my_layout.xml       # layout for large screen size res / layout-xlarge / my_layout.xml     # layout for extra large screen size

In this way we have included layouts for different resolutions for an orientation, default portait , now we must add the folders that contain the layout in landscape. Eventually you will have such a thing.

Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - screen-layout

Now just adapt the layout to the various resolutions, such as if we have to place a button in the same position we should do something like that.

Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - android laypout

 

Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - large layout

Topic: Android and the Various Resolutions – Guid for Developers

 Screen density

For now we have considered only the screen size, but as previously mentioned, there are also different densities. We must therefore manage the pictures or xml file that will be the graphics for all densities. To ease the task here is the main densities used by Android devices:

  • Dp 320: a classic smartphone screen (240×320 ldpi, mdpi 320×480, 480×800 hdpi, etc ..).
  • 480dp: the “tablet screen” Streak (480×800 mdpi).
  • 600dp: the tablet screen 7 ” (600×1024 mdpi).
  • 720dp: the tablet screen 10 ” (720×1280 mdpi, 800×1280 mdpi).

To manage images or graphics xml for various densities we must create the “images” folders for different types of screen, then we will have something like this:

 

Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - Android and the Various Resolutions - Guide for Developers - drawable screen

As we have done for the layout, we can build a directory structure organized in this way. So we have:

  • ldpi: stands for low density (120dpi)
  • mdpi: stands for medium density (160dpi)
  • hdpi: stands for high density (240dpi)
  • xhdpi: stands for extra high density (320dpi)

Topic: Android and the Various Resolutions – Guid for Developers

advanced Techniques

Obviously there may be special cases where we will have the layout that will be for a single density. For example we create a graphic tablet, so a layout-xlarge , which is different for tablet 7 ” compared to those from 10 ”. In this case should not create a folder layout-xlarge otherwise independent of inch tablet, Android will take as layout files contained within it; we will have to create a folder for the graphic tablet 7 ” and another for those with 10 ”. We work on the density and add two folders:

res / layout-sw600dp / layout_activity.xml    # For 7 “tablet (600dp)
res / layout-sw720dp / layout_activity.xml    # For tablets to  10” (720dp)

We also have some perticolari cases relating to the images, we’ll have to manage differently. For example, we all know that with 11 SDK (3.0) we have many more themes available, some have moficato their “main color” going from black to light. So let’s say you create an app that is compatible with the SDK 8 (2.2), we avrere an image to be placed on a black background, on older Android versions such as 2.2 or 2.3, and an image to be placed on a white background for the latest sDK, which from version 3.1 onwards. In practice, we should create a white and a black image, or at least darker. In this case we can create two drawable folders and set their contents according to the SDK in this way:

res / drawable / icon.png           #To all SDK
res / drawable-v11 / icon.png   #Da use the SDK 11, so the 3.0 versions

In any case I recommend to lean more to the official documentation, which you can find this link .

 

About The Author

Related posts

Leave a Reply