0

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?

Fred
  • 121
  • 1
  • 10
  • 1
    "so why does my phone use 615?" -- height calculations might take into account the status bar and navigation bar. "how can I find out in advance which one a given phone will use?" -- there are several thousand Android device models. Worrying about "a given phone" usually is pointless. "Is there a better way?" -- use density-independent units of measure, like `dp`. For many dimensions, they will not need to change at all. Some might vary by screen size (e.g., the margin looks a little small on a tablet). – CommonsWare Apr 23 '16 at 11:04
  • Ok, thanks! So just having one single `dimens` file with units in `dp` (and `sp` for text) is how to do it? I don't even have to worry about the `w` etc (in most cases, I suppose)? – Fred Apr 23 '16 at 11:07
  • 1
    "So just having one single dimens file with units in dp (and sp for text) is how to do it?" -- that's typical. "I don't even have to worry about the w etc (in most cases, I suppose)?" -- you worry about it when the design requires you to worry about it. Or, if you're not doing a formal design, you worry about it when you try your app on different screen sizes and conclude that something ought to be a little (bigger|smaller) on devices with a similar screen size. – CommonsWare Apr 23 '16 at 11:31

0 Answers0