I have put image as background of button. but I don't know at what size of images should I create in Photoshop for all three folders drawable-hdpi,drawable-ldpi, and drawable-mdpi?
Thank you.
If your buttom image is Plain-colored background and if it can be a Stretchable image then Create a bitmap using 9-Patch Tool.
Otherwise, read about Alternate Drawables section on Android developer site:
To create alternative bitmap drawables for different densities, you
should follow the 3:4:6:8 scaling ratio between the four generalized
densities. For example, if you have a bitmap drawable that's 48x48
pixels for medium-density screen (the size for a launcher icon), all
the different sizes should be:
36x36 for low-density
48x48 for medium-density
72x72 for high-density
96x96 for extra high-density
I think this can help you, is a conversion tool, adding image size (mdpi), it gives me the result in pixels for each screen sizes.
http://labs.rampinteractive.co.uk/android_dp_px_calculator/
Hope it helps!
An additional tip for making your life a little simpler in creating images for photoshop. Create your image in mdpi, ie at 160 dpi. This is so because Android calculates pixels as such
px = dp * (dpi / 160).
So basically if u wanna make a button image of the size 48x48, create an image with that size and set the dpi to 160. Once you are done, just change the dpi to 120, 240 and 320 and save your images.
You will not have to waste time calculating what the image sizes should be for different densities.
Related
I did some research and found that there 6 different sizes required by Android to display images properly on all sorts of devices.
LDPI - 0.75x
MDPI - Original size
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
So suppose I have 100x100 image as a baseline (MDPI), then ldpi, hdpi, xhdpi, xxhdpi will be as follows.
LDPI - 75x75
HDPI - 150x150
XHDPI - 200x200
XXHDPI - 300x300
XXXHDPI - 400x400
But I have confusion as to what should be the baseline(mdpi). How do I select my baseline, does it have to be based on something? I can have different images in my app example a back arrow, home arrow, a background image(full screen), an Add icon and so on. But all these icons have to different sizes. So how can I choose my baseline size?
No need to choose, the mdpi(baseline) density means that one dp is roughly equal to one pixel. So we call it the baseline density.
If we provide icon with size by the definition. We will get all the icon image have same physical size on different density screen(ldpi,mdpi,xdpi and so on) with proper quality.
About the background image, I would recommend to put the background image to drawable-nodpi which the image just fill entire screen no matter the density, so just put it there to let the system don`t scale the image and save some memory resources to scale it.
reference Support different pixel densities
Check if this can help you,
Material design icons
I want to use background image in my app.But i am so confused about different screen sizes.I found this question:
Android: Background Image Size (in Pixel) which Support All Devices
But in answer he said xxxhdpi: 1280x1920 px but Lg G3 is xxxHdpi and screen resolution: 1440 x 2560
I need a roadmap.How should be my image sizes for all screens ? (mdpi,hdpi,xhdpi etc.)
Android devices' screen sizes in pixels and screen width in inches, can differ significantly from device to device.
To address this issue, google lets you use different resources per size/density category
See here for some more info.
Generally speaking, you must put the largest size image that you want to support for each dpi in the correct folder, and let android do the resizing.
You can also check the imageView's ScaleType attribute to choose how to scale the image to fit the view.
EDIT
the reason to use the different folders and not just one large image is that the larger the image, the more memory it consumes.
For example a 1920x1280 image is nice to have on a 1920 screen, but on a 320pixels screen the extra resolution is wasted and you have a lot of wasted memory used.
An easier way is to include one single image in your drawable directory, then, in the OnCreate function of your activity, create a bitmap to fit the screen and put it in an imageview that has width and height set to "wrap_content".
This should work for any device.
Read this link. In particular, I think what you're looking for is:
To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density
and also:
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
I'm completely confused to the core reading various articles to understand to get my app to fit in to different screen sizes. basically the issue i am having is to have a logo fit in to screens with different screen densities. I've got an image with a resolution of 1616x369 which fits in to Nexus 7" tablet and nexus 10" tablets I guess because they contain hdpi screen densities(which looks perfectly fine). but if I change the preview on eclipse to a 10" wxvga screen size which seem to contain an mdpi resolution the image gets pixelated. I know this is because I haven't specified an image in the mdpi folder for android to pick it up, hence it picks up the image from the hdpi folder. What I don't understand is to what resolutions should I create images for mdpi and ldpi folders based on my original image.
I'm not exact sure where I got this information from, but I believe there is a link to it within the Iconography | Android Development documentation.
Density Launcher Action Bar Small/Contextual Notification
mdpi 48x48 px 32x32 px 16x16 px 24x24 px
hdpi 72x72 px 48x48 px 24x24 px 36x36 px
tvdpi (use hdpi) (use hdpi) (use hdpi) (use hdpi)
xhdpi 96x96 px 64x64 px 32x32 px 48x48 px
xxhdpi 144x144 px 96x96 px 48x48 px 72x72 px
The size of the images changes depending what type of image you want.
Launcher icons
Action bar and tab icons
Notification icons
Navigation drawer indicator
Generic icons
Depending of where you will use your image it changes the size, so have the correct set for what you are using.
Then don't forget to copy the image to the folders ldpi, mdpi and so on. If you do this right,you will not get images pixelated.
Just go to this site
http://romannurik.github.io/AndroidAssetStudio/index.html
Click in what type of image you want and generate, select one image for example and download, then you can see the correct sizes. Hope it helps you.
I recently had a doubt
I put 40px * 40 px images in drawable folder.
and put 40px * 40 px images in drawable [hdpi] again .
Then Tabhost set this picture
[hdpi] exists and does not exist
Size two pictures displayed on the screen is not the same and why?
They are all the same 40px * 40px
why?
Different folder will result in a different calculation methods it?
PS:[My phone will pre-select [hdpi] folder]
I think you need to create drawable folder in res folder and add all images in drawable folder.
Actually in android there are different resolutions screens and every resolution have fix limitation for retrieving the images on specific folders like - hdpi, ldpi ,mdpi etc. When we create drawable folder in res then if any different resolution screens will occurred then it will pic the image from drawable folder.
If running on mdpi device 150x150 px image will take up 150*150 dp of screen space.
If running on hdpi device 150x150 px image will take up 100*100 dp of screen space.
If running on xhdpi device 150x150 px image will take up 75*75 dp of screen space.
The other way around: say, you want to add an image to your application and you need it to fill 100*100 dp control, you'll need to create different size images for supported screen sizes:
100*100 px image for mdpi
150*150 px image for hdpi
200*200 px image for xhdpi
My app consists of a round ball whose radius I have specified as 35 pixels in the code. The user muse prevent the ball from colliding with other balls.
I have drawn an 800 px by 800 px vector graphic with 72 ppi resolution that I want to use as the bitmap for this image.
What sizes do I scale the image to for the drawable-ldpi, -mdpi and -hdpi folders so that the bitmap is the same size on all devices and also so that the collision detection works fine ? i.e. The app calculates the ball to be 35 pixels but the screen shows a smaller or larger image so the collisions will be all wrong and the user won't know what's going on.
I really don't know much about this so any help will be hugely appreciated.
From the android developer guide:
To create alternative bitmap drawables for different densities, you
should follow the 3:4:6:8 scaling ratio between the four generalized
densities. For example, if you have a bitmap drawable that's 48x48
pixels for medium-density screen (the size for a launcher icon), all
the different sizes should be:
36x36 for low-density
48x48 for medium-density
72x72 for high-density
96x96 for extra high-density
Also, one of the best practices for supporting multiple screen resolutions is: "Do not use hard-coded pixel values in your application code".
Since your applications deals with pixel values at runtime, you might want to read the section Additional Density Considerations and below that section.