Understanding dpi and the drawable folders - android

Yesterday I already asked a question about this here. After that I saw this on the official android developer page:
So you can have a 1024x600px screen device with ldpi and a screen with the same resolution with mdpi.
Furthermore you can have a 600x1024px screen device with mdpi and a screen with the same resolution with hdpi.
I have an image, that takes 20 % of the screen's height and width on every device.
I want to make 5 versions of that image (with different resolution) for each drawable folder.
In my past thread I got this answer:
ldpi: 0.75
mdpi: 1.0
hdpi: 1.5
xhdpi: 2.0
xxhdpi: 3.0
xxxhdpi: 4.0
These are the scale factors.
So if my image has a resolution of 50 x 100 px in mdpi it is supposed to have a resolution of 75 x 150 px in hdpi.
I understand that.
The question now is, how am I supposed to know what resolution my image should have in the mdpi folder, if the resolutions for mdpi are totally different (as you can see in the image above -> from 320x480 to 1280x768).
Thanks !

The drawables should be created at a resolution that makes them the right physical size when displayed on the screen. If you have an icon that is supposed to be 1/2 inch by 1/2 inch on an MDPI screen, then the image should be 80px by 80px. This size should be irregardless of the physical dimensions of the screen; the same drawable on a 1280x768 MDPI tablet is supposed to be 1/2 inch by 1/2inch.
If the icon in question should be larger on the tablet for some reason, then you would need to introduce the drawable-swXYZdp-mdpi folder that Der Golem mentioned above. In this folder, you would be able to create a version of the icon that had a larger physical size (say 3/4 inch) that will be loaded on the tablet.

Related

Different sizes of images in Android

I'm trying to create main activity in my application using GridView. I need to have a grid 3x3. Every cell contains ImageView (icons for different actions). All images must have the same size. And my question is: what sizes of image I must use? I watched tutorial and found a table with sizes for different resolutions and density. But I didn't understand. For instance, I have mdpi density and screen size 480*800. Does it mean that I should use icons 160*266 for this screen? And what sizes should be for other densities and screen sizes? How can I calculate them?
This is one of the most asked question, you can search for more details, but let me give you briefly how it works.
MDPI is considered as the base line and following are the scales
MDPI - X1
HDPI - X1.5
XHDPI - X2
XXHDPI - X3
XXXHDPI - X4
Now you must be thinking what is this.
Since you want to have 3X3 grid with cell of equal size, you can consider the following.
In general mdpi screen size is 360 X 640, so each image size will be 120dp X 212dp Approx.
For mdpi screen, your Image size should be 120px X 212px
For hdpi screen, your Image size should be 180px X 318px
For xhdpi screen, your Image size should be 240px X 424px
For xxdpi screen, your Image size should be 360px X 636px
For xxxdpi screen, your Image size should be 480px X 848px
Now where you should place these images?
Project -> app -> src -> main -> res
Here, create folders with name drawable-mdpi, drawable-hdpi, etc, and place respective images in these folders.
Thats it for supporting multiple screen densities.
According to docs, MDPI and HDPI screen sizes are given considering
their aspect ratio to 3:4, but since most of the users have HD
devices with aspect ratio of 9:16, you can consider the most standard
screen size in Market i.e. 1080 X 1920 which corresponds to XXHDPI and
acts as baseline to make the assumption of considering MDPI to be 360
X 640. For high quality apps, trade off has to be made for lower
devices since most of the existing users have XXHDPI or higher
devices.

android: Galaxy Note 2 : for which pixel layout images/icon should be prepared?

I am developing an app which must support Samsung Galaxy Note - 2.
Now note-2's pixel resolution is 1,280 x 720. Reference Wikipedia.
While developing an app, I found that it was picking images from res/drawable-hdpi.
So for what resolution layout I should prepare the images ? Or do need to make separate resource folder ?
Resources are picked based on DPI a quick reference for what DPI each device uses can be found here:
http://blog.blundell-apps.com/list-of-android-devices-with-pixel-density-buckets/
For image scaling, the images should roughly be sized like so:
if an image is to use 100 dp then the actual images sizes will be:
ldpi: 75px
mdpi: 100px
hdpi: 150px
xhdpi: 200px
if you want to use 100 px on your NOTE 2 then the image sizes will be
ldpi: 50px
mdpi: 66.67px
hdpi: 100px
xhdpi: 133.33px
you can use the following site do do quick calculations:
http://labs.skinkers.com/content/android_dp_px_calculator/
Prepare images for hdpi resolution -- 480x800 hdpi.
Galaxy Note 2 is normal size, xhdpi density and long. You can prepare layout or drawable for xhdpi. For details, please check this post Galaxy Note 2 screen specifications. If you don't have xhdpi resource, android will try to find resource in hdpi.
The Galaxy Note uses hdpi which is a pixel density of 240dpi
Android Device Resolutions

Force load desired dpi drawables according to screen size

I have 4 sets of images
Resolutions DPI Directory
240 x 320 120dpi - drawable-ldpi
320 x 480 160dpi - drawable-mdpi
480 x 800 240dpi - drawable-hdpi
1280x 800 320dpi - drawable-xhdpi
But when I tested it at ASUS transformer with resolution 1280x800 and DPI 224.
It loaded graphics from drawable-hdpi.
If I will add another folder with name drawable-xlarge, It will load desired images but it will increase the size of application as well.
My questions are as follows
1 - What is the best practice to support all screen sizes and DPI?
2 - Is there any way to force load drawable of particular DPI w.r.t screen size?
3 - What is the solution recommended for my problem without replicating the graphics?
But when I tested it at ASUS transformer with resolution 1280x800 and dpi 224. It loaded graphics from drawable-hdpi.
That is because the ASUS Transformer is an -hdpi device. Hence, it is working properly.
What is the best practice to support all screen sizes and dpi?
Usually, images only vary based on density, and so your current structure is fine.
If you elect to have images that vary both on screen size and density, you will need to make more directories (e.g., res/drawable-xlarge-hdpi/) and images for the
Is there any way to force load drawable of perticular dpi w.r.t screen size?
Density and screen size have nothing to do with one another.
What is the solution recommended for my problem without replicating the graphics?
According to your "question", you do not have a problem. Hence, there is no recommendation for your non-problem.

Android: Background Image Size (in Pixel) which Support All Devices

I am creating an Application which will run on all Android Devices. I want to create xhdpi Graphics for My App. My App is full screen. I am confused in Creating graphics. can any one tell me the best sizes of my background image in pixels.
For Example:
xhdpi: 720x1280 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px
Suggest me the best sizes which will appear on all devices good. Because my graphics are the core of my app.
I want that every device get the best image which it want. Android will be not involved in compressing or expanding of image.
The following are the best dimensions for the app to run in all devices. For understanding multiple supporting screens you have to read
http://developer.android.com/guide/practices/screens_support.html
xxxhdpi: 1280x1920 px
xxhdpi: 960x1600 px
xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px
Android Devices Matrices
ldpi mdpi hdpi xhdpi xxhdpi xxxhdpi
Launcher And Home 36*36 48*48 72*72 96*96 144*144 192*192
Toolbar 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 240*320 320*480 480*800 768*1280 1080 *1920 1440*2560
(For good approach minus Toolbar Size From total height of Background Screen and then Design Graphics of Screens )
For More Help (This link includes tablets also):
https://design.google.com/devices/
Android Native Icons (Recommended) You can change color of these icons programmatically.
https://design.google.com/icons/
Check this. This image will show for all icon size for different screen sizes
I looked around the internet for correct dimensions for these densities for square images, but couldn't find anything reliable.
If it's any consolation, referring to Veerababu Medisetti's answer I used these dimensions for SQUARES :)
xxxhdpi: 1280x1280 px
xxhdpi: 960x960 px
xhdpi: 640x640 px
hdpi: 480x480 px
mdpi: 320x320 px
ldpi: 240x240 px
GIMP tool is exactly what you need to create the images for different pixel resolution devices.
Follow these steps:
Open the existing image in GIMP tool.
Go to "Image" menu, and select "Scale Image..."
Use below pixel dimension that you need:
xxxhdpi: 1280x1920 px
xxhdpi: 960x1600 px
xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px
Then "Export" the image from "File" menu.
My understanding is that if you use a View object (as supposed to eg. android:windowBackground) Android will automatically scale your image to the correct size. The problem is that too much scaling can result in artifacts (both during up and down scaling) and blurring. Due to various resolutions and aspects ratios on the market, it's impossible to create "perfect" fits for every screen, but you can do your best to make sure only a little bit of scaling has to be done, and thus mitigate the unwanted side effects. So what I would do is:
Keep to the 3:4:6:8:12:16 scaling ratio between the six generalized densities (ldpi, mdpi, hdpi, etc).
You should not include xxxhdpi elements for your UI elements, this resolution is meant for upscaling launcher icons only (so mipmap folder only) ... You should not use the xxxhdpi qualifier for UI elements other than the launcher icon. ... although eg. on the Samsung edge 7 calling getDisplayMetrics().density returns 4 (xxxhdpi), so perhaps this info is outdated.
Then look at the new phone models on the market, and find the representative ones. Assumming the new google pixel is a good representation of an android phone: It has a 1080 x 1920 resolution at 441 dpi, and a screen size of 4.4 x 2.5 inches. Then from the the android developer docs:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
This corresponds to an xxhdpi screen. From here I could scale these 1080 x 1920 down by the (3:4:6:8:12) ratios above.
I could also acknowledge that downsampling is generally an easy way to scale and thus I might want slightly oversized bitmaps bundled in my apk (Note: higher memory consumption). Once more assuming that the width and height of the pixel screen is represetative, I would scale up the 1080x1920 by a factor of 480/441, leaving my maximum resolution background image at approx. 1200x2100, which should then be scaled by the 3:4:6:8:12.
Remember, you only need to provide density-specific drawables for bitmap files (.png, .jpg, or .gif) and Nine-Patch files (.9.png). If you use XML files to define drawable resources (eg. shapes), just put one copy in the default drawable directory.
If you ever have to accomodate really large or odd aspect ratios, create specific folders for these as well, using the flags for this, eg. sw, long, large, etc.
And no need to draw the background twice. Therefore set a style with <item name="android:windowBackground">#null</item>

Android screen sizes in Pixels for ldpi, mdpi, hpdi?

I've read 10 articles yet still cant find any relation between ldpi, mdpi, hdpi and the actual dimensions in pixels!? Can anybody give a straightforward answer please(if there is one!)
I'm basically trying to put together a splash screen that needs to work on multiple devices without stretching - but i'm struggling as everything I try is either squashed or stretched!?
Cheers
Paul
The ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.
the ratio in pixels between them is:
ldpi = 1:0.75
mdpi = 1:1
hdpi = 1:1.5
xhdpi = 1:2
xxhdpi = 1:3
xxxhdpi = 1:4
so lets take an image with about the size of 100X100:
for mdpi it should be 100X100
for ldpi it should be 75X75
for hdpi it should be 150X150
for xhdpi it should be 200X200
for xxhdpi it should be 300X300
for xxxhdpi it should be 400X400
this way, for screens with the same size but different DPI, all the images seem the same size on screen.
Also you have multiple screen size types small, normal, large, xlarge and each one of them can be ldpi, mdpi, hdpi, xhdpi, xxhdpi (Nexus 10) or xxxhdpi.
You can try to create a splash screen image that fit to each and every screen type
which gives you 4*5 = 20 different images (it seems to much for me).
For now only the Nexus 10 is at the xxhdpi category.
Install ImageMagick and use this shell script to generate your splash and icon files for multiple devices - iOS, Android, Bada and Windows Phone. You can use cygwin/gitbash if you are on Windows
I just did and I'm pretty happy with it :-)
The screen sizes are inside the script and are -
480x800 - screen-hdpi-portrait.png
320x200 - screen-ldpi-landscape.png
720x1280 - screen-xhdpi-portrait.png
320x480 - screen-mdpi-portrait.png
480x320 - screen-mdpi-landscape.png
200x320 - screen-ldpi-portrait.png
800x480 - screen-hdpi-landscape.png
The definitions are:
xlarge screens are at least 960dp x 720dp. large screens are at
least 640dp x 480dp. normal screens are at least 470dp x 320dp.
small screens are at least 426dp x 320dp. (Android does not currently
support screens smaller than this.)
Also, check out this blogpost from Dianne Hackborne:
http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
Probably the easiest thing is to use an image view and set the scaletype to CENTER_CROP.
(Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view).
Make sure that you use the src tag rather than setting the background.
<ImageView
android:id="#+id/home_video_layout"
android:src="#drawable/splash_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>
Updated:
Understanding Screen Densities and the “dp”
Resolution is the actual number of pixels available in the display, density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface. These are interrelated: increase the resolution and density together, and size stays about the same. This is why the 320x480 screen on a G1 and 480x800 screen on a Droid are both the same screen size: the 480x800 screen has more pixels, but it is also higher density.
To remove the size/density calculations from the picture, the Android framework works wherever possible in terms of "dp" units, which are corrected for density. In medium-density ("mdpi") screens, which correspond to the original Android phones, physical pixels are identical to dp's; the devices’ dimensions are 320x480 in either scale. A more recent phone might have physical-pixel dimensions of 480x800 but be a high-density device. The conversion factor from hdpi to mdpi in this case is 1.5, so for a developer's purposes, the device is 320x533 in dp's.
I have found this online dip <--> pixels calculator very useful.
https://pixplicity.com/dp-px-converter/
I support previous answers but don't forget the power of Draw9Patch or using NinePatchDrawables
These refer to screen pixel density, not screen dimension. You need to look into screen size specifiers like small, medium, large, and xlarge instead if you really need to change behavior based on screen size in pixels.
The Android docs explain what densities and sizes match these identifiers.
Android devices can have different width-to-height ratios, while your image has a fixed one. If you do not want your image stretched, you will have to fill the blank spaces above and below or left and right.

Categories

Resources