Not sure if this has been discussed before, but we definitely need a new configuration qualifier for the aspect ratio of the screen. An app can look very different on a 18:9 screen than it looks on a 16:9 screen.

There is an old aspect ratio qualifier (long and notlong) but that doesn't help since even 16:9 devices fall into the long category.

So how do you deal with this issue? Are you using a specific qualifier in your xml layouts? It seems that using the available screen width in combination with the available screen height, we can manage to figure out if the aspect ratio is 18:9 or not, but still this is not ideal.

Does anyone have a reliable solution?

but we definitely need a new configuration qualifier for the aspect ratio of the screen So how do you deal with this issue?

You can always fall back to calculating display aspect ration in your code and then manually applying layout of your choice while calling setContentView(). But I do agree, the qualifier would be the best solution but unless it's there...

  • The thing is that I prefer having a single layout file, while getting the values from the dimensions xml. And I'm trying to figure out which qualifier to use in resources, so that the dimensions will apply to 18:9 devices. – MScott Jan 30 at 16:23
  • @MScott did you find any solution? I'm googling for a proper qualifier for the same reason for an hour now and nothing useful.. – Drusantia May 3 at 10:35
  • Ok I just found it. :D Add "-long" to the qualifier. In my case I have multiple layout files (layout-hdpi, layout-xhdpi, etc), also I added "layout-sw410dp" for bigger phones (1440x2560). For the 18:9 version which is 1440x2880, I use "layout-sw410dp-long". screenshot: ibb.co/fsRm3n – Drusantia May 3 at 10:40
  • Unfortunately the -long qualifier is not reliable, because it will work even for 16:9 screens. I have tested that and I can confirm that. However, in your example you are also using the -sw qualifier, so maybe the combination of these two qualifiers kind of works, but I wouldn't rely on that. What I eventually did is calculating the aspect ratio within my class: aspectRatio = (metrics.heightPixels + navBarHeight) / metrics.widthPixels;, where metrics = getResources().getDisplayMetrics(); and navBarHeight is the height of the bottom navigation bar. – MScott May 3 at 17:13

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.