Scenario
I am developing a random app and recently i encountered a problem. I run a same application on Google pixel 3a xl android emulator and Asus X00TD physical device. And I got to know that in asus phone UI got really changed.
Pixel 3a XL display specs :
Display size : 6.0 inch Resolution : 2160 × 1080 ppi : 402ppi
Asus X00TD display specs :
Display size : 6.0 inch Resolution : 2160 × 1080 ppi : 403ppi
You see It's almost same only ppi is different and i don't think so that will make some big difference. roughly 6 pixels will be affected and that's not gonna change whole UI. I don't know the dpi
resolution of the asus x00td. And I can't find on internet too.
This is the UI difference between pixel 3a xl and asus x00td.
As you can see there's big difference between emulator and physical phone. So, I have 2 questions
There's a way to calculate dpi by function. but, What if I don't have a phone and still want to know dpi res of that phone?
Why there is a big difference between emulator and physical phone?
EDIT
I tried to calculate it on internet but, it gave me 0.0631mm
dot pitch. which i am not able to understant what it is. Also emulator shows that pixel 3a xl has 400dpi
resolution.
So, What is difference between 400dpi
and 0.0631mm dot pitch
?
SOLUTION I TRIED
I tried to emulate the asus device in emulator by setting smallest width to 360dp. Initially it looked same as asus. and emulator was picking xhdpi
file of dimens.xml
. So, I made changes in dimens.xml
of xhdpi
but, asus didn't pick that file. instead it picked xxhdpi
file. Which is used in another device Realme 3 pro. I can't modify xxhdpi
file because it's gonna mess up UI for all the 6+ inch display phones. and at the same time asus is still picking xxhdpi
file and asus's UI is messed up.
Can't find a solution to this.
As explained upper by snachmsm, Layout qualifiers are most helpful in acheiving display responsiveness.
In my case it was the asus x00td which wasn't displaying the content correctly. SO, to fix that,
I used
height
qualifier value ofheight
which resulted in minimum height.. So, devices with height of600dp
or above will be usingdimens.xml(h600dp)
. So, asus picked up this file. As well as I created file for700dp
as well which has slighly bigger dimensions for large display like realme 3 pro.Plus I used constraint layout guidelines percentages to rearrange views in manner that margins will be adjusted automatically.
So, dimensions and sizes are controlled by dimens.xml and margins are automatically controlled by constraint layout.