I am using a 100x100 pixel image to display something on the only device I support, the 3.2" 240x320 pixel LG E430. I found some strange behaviour though. If I put that image in the drawable-ldpi folder, it will be rendered larger than when I put it in my drawable folder.
Is this intended? And if so, how should I scale my images so they get rendered correctly, but still can reside in the drawable-ldpi folder?
putting image in drawable folder should be treated as drawable-mdpi, that's why if you put your image in drawable-ldpi it would be larger.
Edit:
In order to put the image in drawable-ldpi and having the same size as it was put in drawable, scale the original image from 100 x 100 to 75 x 75.
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
Related
So I need to create images to be part of my app that I'm making. I haven't found the answer anywhere.
What I am wondering is...
If I created an image that is to be displayed on Activity1, then what image size in PIXELS should I created the initial image at?
The initial image would then be resized to their corresponding DPI to work well on Android phones.
I may be doing this wrong in creating images so they don't lose their quality, any ideas?
If I am doing this wrong, then please can someone advise on the best practice on creating Android images in pixels and then converting to DPI later after the initial image?
Thank you! :)
EDIT: This question is different because I'm mainly talking about keeping image quality by making the image big first and then downsizing.
You have to create six generalized size image densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
For more detail check out this link
To generate image for Android device you can follow this as I do:
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
144x144 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density (launcher icon
only; see note above)
Or,
Image resolution and DPI are tightly coupled each other. There is a 3:4:6:8 scaling ratio in drawable size by DPI.
LDPI - 0.75x
MDPI - Original size
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
For example if a 100x100 image is a baseline (MDPI),
LDPI - 75x75
HDPI - 150x150
XHDPI - 200x200
XXHDPI - 300x300
XXXHDPI - 400x400
and so on.
I know we have some standard of DPI that we can use it for support multiple screen size in an like :
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
But when I calculate for some real device, e.g. LG G3 - it has DPI is 538.
So my question is do we need to use that exactly DPI number for scale the image,... or just let it be one of xxhdpi (480dpi) or xxxhdpi (640dpi).
For my opinion, I think you shouldn't care about information dpi of devices. You should only focus to provide images, size (dp,sp) etc for some type of screens :
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
=========================================================================
Example:
As you maybe known that 1 px = dp (dpi/160)
So if you have an image with size is 32 x 32 px on screen 160 dpi. It's mean your image get size 32 x 32 dp.
Now you want to scale it on xxhdpi (extra-extra-high) ~480dpi.
On xxhdpi (extra-extra-high) ~480dpi : 1 px = dp(480/160) = 3dp
Then you only need to provide another image with size 32*3 x 32*3 px = 96 x 96 px
You just have to provide the right assets and android will take care of the rest. You can check the documentation for more details.
The Android system helps your application achieve density independence in two ways:
The system scales dp units as appropriate for the current screen density
The system scales drawable resources to the appropriate size, based on the current screen density, if necessary
So in your case its better to provide both the assets. At runtime, the system uses the appropriate resources for your application, based on the generalized size or density of the current device screen.
I've developed a test app to understand android screen density related things. I've values.xml and strings.xml having respective test data in following folder structure :
values\dimen.xml (100dp)
values-mdpi\dimen.xml (100dp)
values-hdpi\dimen.xml (150dp)
values-xhdpi\dimen.xml (200dp)
values-xxhdpi\dimen.xml (300dp)
I am showing these data on UI to know from which folder app is taking data for differetnt screen sizes and densities. So, i'm getting following result :
1st device
2nd device
Problem is 2nd device with xxhdpi is showing me 900dp value, but in values-xxhdpi\dimen.xml value is 300dp?
900 is a pixels value. Your One PLus 2 have density 3, it means 300dp == 900px
If It didn't pick up the correct layout use values folder like this
values
values-ldpi
values-mdpi
values-hdpi
values-xhdpi
//added folders
values-w300dp-mdpi
values-w600dp-mdpi
Add the folders as required
Sony Xperia J has 245 dpi screen and OnePlus 2 has 401 dpi screen, so there's something wrong with these values.
Densities are as follows:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
So it's correct that your app takes images from hdpi for Xperia J and xxhdpi directory for OnePlus 2. Read more here: http://developer.android.com/guide/practices/screens_support.html
i want to create a folder values, only for 240dpi screens, and if it is bigger that that so use other folder like 480..
The "values-sw240dp" folder is not working to me.
My main goal is to set different dimens values for 240dpi screens.
Thanks ahead.
You are using wrong folder names.
Dpi densities qualifiers have following values
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
You should name your folder values-hdpi
Using configuration qualifiers
values-sw240dp means screen smallest width is 240dp
I'm trying to display an image in an ImageView on 10' lenovo yoga. In each drawable folder I have put an instance of the same image with different sizes:
ldpi: 184 x 294
mdpi: 248 x 397
hdpi: 375 x 600
xhdpi: 496 x 794
xxhdpi: 800 x 1280
The images are the screenshots I've taken with the same device with xxhdpi image being the original image. The problem is instead of loading the image from a high res folder it is loading the image from mdpi and thus the result is blurry. Why is it doing this?
The drawable folders refer to screen density I believe. At http://developer.android.com/guide/practices/screens_support.html it says,
A set of six generalized densities:
ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi
I looked up the specs of the 10' lenovo yoga and depending on the one you own, the screen density will be different. For example the Yoga 10 has 149 ppi and the lenovo yoga 2 pro has 276 ppi. So that could be the reason why it's pulling from the lower resolution drawable folders.