Tips & Tricks: Screen sizes

Hi Android developers,

Last week was hectic, we needed to reinstall and reconfigure the backend server of Perka’s File stash.

This week we will take a little twist and we will talk about a topic that is more focused on design: Screen sizes.

When designing Android apps the best practice is to use Density-independent pixel (dp) as measure. A dp is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a “medium” density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160).

Another best practice is to use wrap_content and fill_parent in XML so the layout will scale automagically. Also a RelativeLayout is a good practice, it will keep the distances the same even if the screen is bigger or smaller.

Also keep in mind of using layout and orientation qualifiers, which can be added to the /res/ directory. This will make it easy to make to make a different layout for another screen size and/or orientation.

For images used in for the different screens, you might want to use draw9patch to make image.9.png files. These files are processed by the tool and you can assign how it will be stretched.

Another good practice is to use Fragments, this will allow you to reuse designs in different layouts. You can combine the fragments in a layout or just use 1 fragment as layout.

Extended information can be found at: Supporting Multiple Screen Sizes and Android Training Multiscreen

Kind regards,
PullesSon – Android

Tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply