0

The android app design am working, is on a screen size of 1080X120 with 72(pixles/inch) as the resolution. All the icons, images, texts are in pixels. Now the developer wants all of them in dp and not px. Now how do i convert them? And is the screen size am using is the right one?

2

1 dp (density-independent pixel) = 1 pixel at 160 PPI (or mdpi)

From developer.android.com

Density-independent pixel (dp)

A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.

The density-independent pixel 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). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.

Since Android apps can be seen on any number of screens, all with different sizes and resolutions, declaring all your sizes in literal pixels doesn't make much sense as they would appear at completely different physical sizes—hence the density-independent pixel.

The easiest way to get your dp values would be to set up your Photoshop document at the correct physical dimensions (i.e cm or inch) at 160PPI (or simply at the mdpi pixel dimensions for your screen). Your pixel values then translate to dp 1:1.

If your PSD is set up at a different resolution then there are calculators that will work out the different pixel sizes and the dp value for you. http://androidpixels.net is a quick and easy one.

As for your screen size, unless you're designing for one specific device, there is no correct size. If you are designing for a specific device, use the screen size of that device... Otherwise pick a size and design your UI with the knowledge that the screen size isn't static.

  • cai: Thank you for the reply, i totally understood. Appreciate for the detailed reply. – user7370 May 27 '16 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.