I am working on optimising layouts for multiple screens, and I'm stuck on how to define the different dimens
files. So, it says on android developer that you should use sw<N>
, w<N>
or h<N>
, but how can I find out in advance which one a given phone will use?
I have an Sony LT26i, which has screen resolution 720 x 1280, and it uses (by trial and error) the qualifiers w<360>
and h<615>
. I'm not entirely sure, but I would guess that 360 is backwards calculation of the px formula, i.e. px = dp * (dpi / 160)
(360 = 720 * 160 / 320
, where 320 is the DensityDpi
as per the DisplayMetrics
class). However, when I apply the same logic to the width, I get 640, so why does my phone use 615 (which corresponds to a dpi
value of 333.00813)? Or do width and height have different dpis?
For optimising, how do I choose what steps to define my dimens
files? I'm considering basing my calculations on my own phone(s) pixel values, create steps based on given screen densities using the px formula (above) and just scale the values based on the ratios given (i.e. from ldpi to xxxhdpi .75:2:3:4:6:8
), possibly adjusting individual values depending on how things progress. Is there a better way?
Are there recommendations for specific configurations of AVDs and dimens
to test the app on?