logo

Mobile: A New Unit of Measurement

If you get in to mobile development, in particular with Android, one of things you need to get used to is the variety of screen sizes out there. Not only the size of the screen, but - more importantly - the DPI or Dots Per Inch (aka "density").

If you define screen layout and font sizes in terms of exact pixels then it will look ok on one screen but not scale up or down to others with larger or smaller screens, respectively.

In steps the unit of measurement known as Density-independent Pixel (aka "dp" or "dip"). Where 1px = 1dp * (dpi / 160). So 1 dp is the same as 1.5 px on a 240 dpi screen and 0.75px on a 120 dpi screen.

In Android you can then do this:

<TextView  android:text="Large Text" android:textSize="35dip" />

You then know it will appear a consistent size across all displays. Here's an example of one app running on a HTC Hero-sized phone and on a Galaxy S2-sized phone. Notice how they scale.

dip

The whole screen size issue with Android takes a bit of getting the old head round, but if you're going to get in to Android development you can't avoid it and need to fully read and understand this guide.

Comments

  1. Different but refreshing. It's the way it ought to be, really, in my mind. If I'm developing a UI with a lot of deliberation, I don't want something random like device resolution spoiling it. Thanks for sharing the info! I haven't had a chance to do real native phone dev yet. Still doing web for Blackberry.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Fri 29 Jul 2011

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content