Zbarcea Christian
Zbarcea Christian

Reputation: 9548

Understanding android layout and drawable resources

I have read many articles, documentations, tutorials but I am still confused about how android uses layouts and drawable.

Please correct me if I am wrong !

I know DPI stand for (density independent pixel) dp == dpi (no difference). So, that means if two devices with same size but different densities will produce the same object size (ex. ImageView) but in different quality?

enter image description here

If I am right, that means if I have an image, I should put the picture with the highest quality in res/ldpi, and the other picture with lowest quality in res/mdpi folder? What is the difference between images that are in res/mdpi and res/hdpi? Sizes, quality or what?

Upvotes: 0

Views: 1340

Answers (1)

type-a1pha
type-a1pha

Reputation: 1893

Let's say you have an image and want to display it the same size regardless of your device dpi. Then you use dp to ensure this. Since the size is the same, let's say 1 cm, in the low dpi device there will be less pixels in that cm, let's say 160, thus a lower resolution image will be enough. In particular a 160x160 pixel image will be the right size.

In a higher dpi device, e.g. with 200 pixels per cm, you will need a higher resolution version, or better you can use a higher resolution image, for example a 200x200 one.

They will still e the same size, but the one in the hdpi device will have more details.

Here you find the ratios you should consider when resizing your images (many tools can do this automatically):

http://developer.android.com/training/basics/supporting-devices/screens.html

The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 1.5"x2" screen), providing the baseline of the system's display. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc.

Upvotes: 2

Related Questions