Android image size confusion - android

I'm very confused about making drawables for Android.
Let's say I want to make a big image that will fill 30% of the screen, or a certain amount of dp, like 300dp.
What size should that image be in pixels for each screen density, and in what dpi should I save it in?

For 300dp, you need:
300px for mdpi (1x)
450px for hdpi (1.5x)
600px for xhdpi (2x)
900px for xxhdpi (3x)
1200px for xxxhdpi (4x)

https://developer.android.com/guide/practices/screens_support.html
ldpi - 0.75 * mdpi ,
mdpi - 1 * mdpi ,
hdpi - 1.5 * mdpi ,
xhdpi - 2 * mdpi ,
xxhdpi - 3 * mdpi ,
xxxhdpi - 4 * hdpi ,
so if you want to generate for mdpi screen to be 300dp the image should be resized according to the above calculation

Related

Understanding Drawables and Images sizes

Firstly I did a lot of search to understand how it work, but I don't find simples tutorials. An exemple, this view:
These are my drawables folders:
The selected device is: Pixel 5.0 1080 x 1920 (xxhdpi).
Immagine in this resolution (1080 x 1920) I set the image view on the top in blue color (Solutis) with 700px of width and 250 px of height, how I have to resize this images for each drawables folders ?
I found this informations:
LDPI - 0.75x
MDPI - Original size // means 1.0x here
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
And
LDPI: Portrait: 200 X 320px
MDPI: Portrait: 320 X 480px
HDPI: Portrait: 480 X 800px
XHDPI: Portrait: 720 X 1280px
XXHDPI: Portrait: 960 X 1600px
XXXHDPI: Portrait: 1440 x 2560px
Here I don't understand why when I select my vistuel device 1080 x 1920px on the Design Edit it say xxhdpi and xxhdpi is 960 X 1600px...
And what gonna be the different sizes of the image for the differents drawables ?
If someone can publish a project exemple, I wool look on, please.
Did you check the documentation? Here is the interesting part:
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.
This means if your device as a higher density a bigger image will been chosen.

Image resolution for mdpi, hdpi, xhdpi and xxhdpi

I have a background for my app in resolutions 720x1280 pixels, 1080x1920 pixels and 1440x2560 pixels.
In which folders (mdpi, hdpi, xhdpi and xxhdpi) should I put each background?
Please read the Android Documentation regarding screen sizes.
From a base image size, there is a 3:4:6:8:12:16 scaling ratio in drawable size by DPI.
LDPI - 0.75x
MDPI - Original size // means 1.0x here
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
For example, 100x100px image on a MDPI will be the same size of a 200x200px on a XHDPI screen.
Require Screen sizes for splash :
LDPI: Portrait: 200 X 320px
MDPI: Portrait: 320 X 480px
HDPI: Portrait: 480 X 800px
XHDPI: Portrait: 720 X 1280px
XXHDPI: Portrait: 960 X 1600px
XXXHDPI: Portrait: 1440 x 2560px
Require icon Sizes for App :
http://iconhandbook.co.uk/reference/chart/android/
DP size of any device is (actual resolution / density conversion factor).
Density conversion factor for density buckets are as follows:
ldpi: 0.75
mdpi: 1.0 (base density)
hdpi: 1.5
xhdpi: 2.0
xxhdpi: 3.0
xxxhdpi: 4.0
Examples of resolution/density conversion to DP:
ldpi device of 240 X 320 px will be of 320 X 426.66 DP. 240 / 0.75 = 320 dp 320 / 0.75 = 426.66 dp
xxhdpi device of 1080 x 1920 pixels (Samsung S4, S5) will be of 360 X 640 dp. 1080 / 3 = 360 dp 1920 / 3 = 640 dp
This image show more:
For more details about DIP read here.
Check the image above I hope it will help someone.
Link to the whole article itself
Your inputs lack one important information of device dimension.
Suppose now popular phone is 6 inch(the diagonal of the display), you will have following results
DPI: Dots per inch - number of dots(pixels) per segment(line) of 1 inch.
DPI=Diagonal/Device size
Scaling Ratio= Real DPI/160.
160 is basic density (MHDPI)
DP: (Density-independent Pixel)=1/160 inch, think of it as a measurement unit
in order to know the phone resolution simply create a image with label mdpi, hdpi, xhdpi and xxhdpi. put these images in respective folder like mdpi, hdpi, xhdpi and xxhdpi. create a image view in layout and load this image.
the phone will load the respective image from a specific folder. by this you will get the phone resolution or *dpi it is using.

Need advice for Android multiple resolution design

For example, I'd like to show an image in screen. Here are the size and dpi:
LDPI - 0.75x 75x75 120 dpi
MDPI - Original size 100x100 160 dpi
HDPI - 1.5x 150x150 240 dpi
XHDPI - 2.0x 200x200 320 dpi
XXHDPI - 3x 300x300 480 dpi
XXXHDPI - 4.0x 400x400 640 dpi
But the display for two devices is not what I want.
The first device is 480x800, 240 dpi. The second device is 800x1280, 213 dpi.The bigger screen has lower dpi. I need some advices on how to handle this case? Thanks
What I see is that your first device is a mobile while the second is a tablet. So you can provide alternate layout files for mobile's and tablets. See supporting multiple screens for more information. For this case for mobile you can use layout-sw720dp folder and for the bigger tablet screen. As for the images your current settings above will work great.

Screen size and dpi of bitmaps

I found two approximations of how developer should support bitmaps for different screen sizes. One is this:
ldpi low density 120 dpi
mdpi medium density 160 dpi
hdpi high density 240 dpi
xhdpi extra high density 320 dpi
The other is this:
xhdpi: 2.0
hdpi: 1.5
mdpi: 1.0 (baseline)
ldpi: 0.75
This means that if you generate a 200x200 image for xhdpi devices, you
should generate the same resource in 150x150 for hdpi, 100x100 for
mdpi and finally a 75x75 image for ldpi devices
Does it mean that If I take as a baseline 640x360, I have to make following 4 groups of images:
1) ldpi - size 480x270 pixels and density 120 dpi
2) mdpi - size 640x360 pixels and density 160 dpi
3) hdpi - size 960x540 pixels and density 240 dpi
4) xhdpi - size 1280x720 pixels and density 320 dpi
You are misunderstanding.
The documentation is not saying different things. The second part you reference is telling you how much bigger an image is in relation to the base density of mdpi
e.g xhdpi fits 2x the amount of horizontal and vertical pixels into the same space that mdpi would.
mdpi = 160 dpi (scale factor 1)
xhdpi = 320 dpi (x2 twice as dense as mdpi therefore an image in this folder needs to be twice as high and twice as wide as its mdpi counterpart to appear the same size on an xhdpi screen)

Android background image size in pixel

I would like to create a background image for different resolutions in Android. So I need the values (in pixel) for ldpi, mdpi, hdpi,xhdpi and xxhdpi. It is important that the image will not be blurred.
I have already read the Documentation about multiple screen support but there are sizes in dp instead of pixel.
Try follow below android icon graphy size reference for various device screen resolutin.
ldpi mdpi hdpi xhdpi xxhdpi xxxhdpi
Launcher And Home 36*36 48*48 72*72 96*96 144*144 192*192
Action Bar And Tab 24*24 32*32 48*48 64*64 96*96 128*128
Notification 18*18 24*24 36*36 48*48 72*72 96*96
Background 320*426 320*470 480*640 720*1280 1080*1920 1440*2560
there is no full list of screen resolutions, there are no fixed values in pixels for ldpi, mdpi, hdpi,xhdpi and xxhdpi. Every android device may have different resolution. If you want to fill all resolutions you will have to create too many images. If you put them in your app, it will make the app size huge. Maybe a better approach is to use composite image for background.
According to android documentation
mdpi is baseLine size
we can use it to measure all other scales , that mean if mdpi (scale 1) equal 1 xhdpi (scale 2) should equal 2 , multiplay mdpi sizes in scale value
all sizes width x height in pixel
xxxhdpi: 1280x1920 px // 4x
xxhdpi : 960x1440 px // 3x
xhdpi : 640x960 px // 2x
hdpi : 480x800 px // 1.5 x at least 480x720
mdpi : 320x480 px // baseline = 1x
ldpi : 240x360 px // .75 x
** notice I add xxhdpi with 3.0x scale to image*
xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px
i think it is rather easy to convert the DP into pixels in andorid java i am achieving this with this function that i created
int getPixels(Context context, float dp) {
return (int) (context.getResources().getDisplayMetrics().density * dp + .5f);
}
hopefully this is helpful for people,
and kindly do share your views on it, as i would like to get this conversion as accurate as possible, thankyou

Categories

Resources