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
Related
I am using ImageView With width="Match_Parent" & Height="200dp" and ScaleType="Fitxy" in my xml file,Exactly what resolutions(In pixels) should in use for MDPI,HDPI,XHDPI,XXHDPI,XXXHDPI for this particular insistance.
Thanks in advance!
Well that depends on the base image you are using.
To calculate pixles for different screen sizes use the below formula:
px = dp * (dpi / 160)
list of dpi respective to screen sizes:
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 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
Android Export
XXHDPI - 100% baseLine
XHDPI - ?
HDPI - ?
MDPI - ?
LDPI - ?
Plz say anyonce of these sizes
I'm not sure, but don't you need the resolutions of the images?
If so, may I link you to Android Developer support?
You can get a lot of information here:
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
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 (launcher icon
only; see note above)
Image example:
Now, lets post this, and calculate the rest!
Edit:
I made a simple calculation with Excel
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