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
Related
I am working with a graphic designer at the moment who is trying to verify what sizes images I am currently using in my app so he can create new images in the right size for all resolution modes (designing the image at the smallest size and then scaling it for the other modes).
In my app, I am emulating a device that is 720 x 1280: xhdpi, and on this device, an ImageView is set to size 50dp x 50 dp.
Is it correct to say 50 dp xhdpi -> 25 dp mdpi? 100px? Or 50px? What exactly? What is the correct size that we should be making for the smallest size?
According to Android Documentation.
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
According to the upper difference you can calculate the ImageSize resoultion.
Update :
you have create different size of Image like HDPI, MDPI, XHDPI. but that is not mean that you can set ImageView Height and Width according to it's Drawable.
Example :
let's some device have small screenSize but it is high density support so you have to set high resolution density Image but the Size of the ImageView you have create small in that case.
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
I'm a beginner developing an Android app that needs to display a clip art type png image the full width of the screen in both portrait and landscape mode:
Portrait:
Landscape:
Would I be right in saying that in order to cater for each screen resolution and orientation I need to include the following image sizes?:
Image width: Resource folder:
xxhdpi – 1920 px drawable-land-xxhdpi
xhdpi – 1280 px drawable-land-xhdpi
xxhdpi – 1080 px drawable-xxhdpi
hdpi – 960 px drawable-land-hdpi
xhdpi – 720 px drawable-xhdpi
mdpi – 640 px drawable-land-mdpi
hdpi – 540 px drawable-hdpi
ldpi - 480 px drawable-land-ldpi
mdpi – 360 px drawable-mdpi
ldpi - 270 px drawable-ldpi
This seems overkill. The App could have a thousand of these images and thats 10 versions of each.
What is the normal approach in this scenario?
Would you scale the images to suit?
Assuming you will maintain the same aspect ratio regardless of whether the screen is in portrait or landscape orientation and you will be displaying the image via an ImageView, you will only need 4 versions of each image - xxhdpi, xhdpi, hdpi, and mdpi.
As far as the image widths go, stick with the 2:3:4:6:8 scaling ratio recommended here, in the Android Documentation. That link specifically discusses icons, but the scaling ratio holds true for all images. So if you are using an image width of 640 px in landscape on mdpi, the hdpi, xhdpi, and xxhdpi should have widths of 960 px, 1280 px, 1920 px, and 2650 px, respectively. Don't worry about a ldpi version because Android will scale down the hdpi version for low resolution devices.
Last thing, set the scale type of the ImageView to a scale type which will maintain the image's aspect ratio (CENTER_CROP or CENTER_INSIDE). See the ImageView documentation for info about setting the scale. Then once you set the image to fill up the width of the screen, the image should appear as you would like.
Which icon size will be preferable to support different screen sizes in Android? The dimensions provided:
ldpi-36*36 px
mdpi-48*48 px
hdpi-72*72 px
xhdpi-96*96 px
worked fine for launcher icon but not for icons inside the app like ImageButtons. Can anybody help me to find out correct dimensions for ImageButtons? Thanks in advance..
You should use dp instead of px. 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.
Conversion: px= dp * (dpi / 160)
For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels.
ldpi: 24*24 px NORMAL*0.75
mdpi: 32*32 px NORMAL
hdpi: 48*48 px NORMAL*1.5
xhdpi: 64*64 px NORMAL*2
manually you can calculate your sizes using the conversion from above
After searching a lot I found the link where I got expected and useful information.
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>