Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android different drawable screen resolutions

I'm a bit confused as to what resolutions I should be saving my images in for the different drawable folders. Is there a general formula for it? For example,if I want an image to take up 10% of the height and the full width of the screen, roughly how would I calculate what different resolutions I should save the image in?

like image 367
CoffeeCrisp Avatar asked Dec 11 '12 16:12

CoffeeCrisp


People also ask

How do I make my Android apps fit all screen sizes?

Simple, use relative layout with the set margin code. Set the margins between each text view, button, etc and it will look the same on every phone. android:layout_marginTop="10dp" // change Top to Bottom, Left or Right for what you need.

Is dp the same as PX?

Definitions. px or dot is a pixel on the physical screen. dpi are pixels per inch on the physical screen and represent the density of the display. dip or dp are density-indenpendant pixels, i.e. they correspond to more or less pixels depending on the physical density.

What is 4x pixel density?

In 4x screen (~640 DPI) it takes four times as many pixels (352 x 144 PX) to fill the area of 88 x 36 density-independent-pixels.


2 Answers

This is android's guidelines for icons. Obviously not all drawables are icons, but maybe this helps you get started.

  • 36x36 for low-density
  • 48x48 for medium-density
  • 72x72 for high-density
  • 96x96 for extra high-density

enter image description here

From here: http://developer.android.com/guide/practices/screens_support.html

like image 151
NeilMonday Avatar answered Sep 21 '22 05:09

NeilMonday


According to android documentation here

http://developer.android.com/guide/practices/screens_support.html#range

In mdpi (baseline density) 1px = 1dp

and under topic 'Range of screens supported' least resolution for a normal size screen(baseline size) in dp is

470dp X 320dp and since in baseline density 1px = 1dp so baseline screen size in pixels would be

470px X 320px

now for baseline screen size and density 10% of 470px would be 47px and full width is 320px so your baseline drawable will have the following size in pixels

47px X 320px

The scaling ratios for alternative drawables is 3:4:6:8 for ldpi:mdpi:hdpi:xhdpi

this means that the above baseline resolution of your graphic is at scale 4. Now to get resolutions for your graphic in other densities we need to divide the mdpi graphic resolution with 4 to get the unit values

height unit = 47/4 = 11.75

width unit = 320/4 = 80

now reoultions in other densities can be calculated by multiplying unit values with respective scaling ratios

ldpi

11.75 X 3 = 35.25px

80 X 3 = 240px

mdpi (already calculated above, doing it again here for clarity)

11.75 X 4 = 47px

80 X 4 = 320px

hdpi

11.75 X 6 = 70.5px

80 X 6 = 480px

xhdpi

11.75 X 8 = 94px

80 X 8 = 640px

like image 43
Nouman Hanif Avatar answered Sep 21 '22 05:09

Nouman Hanif