android Supporting Multiple Screens Calculation - android

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

Related

Designing icons for android

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

How can I set the resolution for the different screen size in android

I know that my question is very simple But my question is not for example about how to support multiple screen sizes in android or like this. I know that we should put the launcher icon in the minmap folder instead the Drawablefolder and there are standard sizes in android for the icons.
MDPI: 48x48
HDPI: 72x72
XXHDPI: 144x144
XXXHDPI: 192x192
But if I create an image with paint program in windows and its resolution is 1920 * 1080, as the result it is very big for android.Now my question is, Should I change the 1920 * 1080 resolution to the 48 * 48 resolution by another program? Or If I put the 1920 * 1080 resolution in the minmapfolder in a android project, Does the minmap folder in the android studio changes the 1920 * 1080 resolution for example to the 48 * 48 resolution?
Excuse me If my question is simple.
Those 'standard sizes for icons' are for action bar icons or icons of similar size, but what they do show is the ratio of images/icons for different screen sizes. An image with resolution 1920 * 1080 is likely not an icon but rather a background image, but you should either simply put your image in one of the drawable folders and the OS will scale the image respectively for each screen size, or you can include one image in each drawable folder than follows the recommended ratios.
If you put your image in the /drawable folder, instead of mdpi/hdpi folders the, that image will be scaled automatically depending on your device resolution so if your device is mdpi the image would be scaled down so you will save some memory.
So you can just put the image in the /drawable folder and dont mind it.

Relationship between image resources and their resultant size on screen

Say I have a cat.png in my drawable-hdpi folder, with dimension 100*100 px. Now if I load this picture using an ImageView whose size is set to "wrap_content":
cat_image.setImageResource(R.drawable.cat);
How can I know the size of the image view (in pixels) without calling "getHeight()"? There must be a relationship between the size of image view and the number "100", but I tried to convert "100" from DP to PX, and from PX to DP, etc, with no success.
if a image is 100px that in mdpi is 100dp.
Then something that is 100dp means:
its 100px on mdpi
its 150px on hdpi
its 200px on xhdpi
So android will try to find the best suited resource to use. for drawables it also scales the image automatically so that if you have it as 100px and placed in mdpi it will use it for hdpi screens but make it 150px. This is not recommended and you should always try to have all the resources into all of the folders (mdpi hdpi xhdpi).
There is a helper method that can help you convert 100dp into pixels through code.
Converting pixels to dp

adding image resources and using one as a layout background

so im working on my first app and i have a question about images
first off, theres 4 different drawable folders, do i just drop an image into one of them? what is the proper way of adding a resource image?
secondly, i know theres a bunch of different resolutions for phones. should i just use one that is say, 960x720dp? or is there another appropriate way of doing this? i want to add an image as a resource into my project, then use it as the background for my app layout...
The best way is to put 4 different versions of the image in the 4 folders . The simplest way to find out what resolution each folder must have is to use mdpi image as a reference and multiply other 3 like this:
ldpi = mdpi x 0.75
mdpi = this is the reference resolution
hdpi = mdpi x 1.5
xhdpi = mdpi x 2
Example: for an image that has 100 x 80 px as the base image, the other folder sould contain images with the following res:
ldpi = 75 x 60 px
mdpi = 100 x 80 px this is the reference image
hdpi = 150 x 120 px
hhdpi = 200 x 160 px
The best way is to create the biggest image in you image editor that you will need and make smaller variants from that. you can fint you own mathematical formula for the multiplication
If you don't want to put different variants for the image then let Android OS convert the images for you The Android OS will search the reference image in mdpi folder so make sure to put the image in this folder
More info here
You just need to paste your images into drawable folders.
To address different resoulutions, you can place different images into different drawable folders with same name, say for logo.jpg into drawable-ldpi might have image logo.jpg with resolution fit to ldpi, and drawable-mdpi have image logo.jpg with resoluiion fit to mdpi. or if any image must be same for all resolutions then place a single image into any of the drawable folder.
You can do this by adding just one images in any folder but this link of supporting multiple screens and resolution of images provide you the best way to do that. Just read that

Button Image size in android

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.

Categories

Resources