Issue
My project has five layout directories under src/main/:
layout
layout-long-land
layout-long-port
layout-notlong-land
layout-notlong-port
... each of which contains a file named "layout_main.xml". Each of the layouts contains a TextView whose value indicates which layout Android is actually using.
My problem: EVERY device is using layout-notlong-land and layout-notlong-port (depending on current orientation), including my (very, VERY widescreen) Nexus 6p and my 16:10 Xoom (which, AFAIK, should be using layout-long-land and layout-long-port).
For what it's worth, I have API 15 set as the minimum, and API 23 as the build/target SDK.
The Xoom is running 4.1, the Nexus 6P is running 6.1, and my one "genuinely notlong" tablet (a Teclast x89 with 1080x1440 4:3 display) is running 4.4.
What am I doing wrong?
Update
I did an experiment. I deleted the layout-long-land and layout-notlong-land directories, renamed layout-long-port to layout-long, and renamed layout-notlong-port to layout-notlong.
Result: same as before. All three devices are using the "notlong" layout.
Update 2
I tried two more devices, did more research, and came up with an answer that's a "solution" only insofar as it might someday spare somebody else from burning 4 hours attempting to solve a hopeless problem.
Solution
Well, I think I figured out what I was doing wrong... I naively assumed Google used common sense in its definition of "long" vs "notlong".
I tested two additional devices:
Samsung Galaxy Note 4 (same display as the Nexus 6p) correctly used the "long" layout.
Samsung Galaxy Tab 3 (8") used the "notlong" layout.
Determined to explore the problem further, I compared the DisplayMetrics from all 5 devices & got the following results for resolution, density, DPI, and aspect ratio (long/notlong in parentheses indicates a result that I don't agree with):
| Nexus 6p | 2392x1440 | 3.5 | 515dpi | 1.66 | (notlong)
| Note 4 | 2560x1440 | 4.0 | 640dpi | 1.78 | long
| Teclast x89 | 1368x1080 | 1.5 | 240dpi | 1.27 | notlong
| Galaxy Tab 3 (8") | 1280x800 | 1.33| 213dpi | 1.6 | (notlong)
| Motorola Xoom | 1232x800 | 1.5 | 160dpi | 1.54 | (notlong)
| Generic 1920x1080 | 1920x1080 | --- | ------ | 1.78 | long
| Arbitrary 5:3 | --------- | --- | ------ | 1.67 | long
According to Android resource notlong / long identifiers not working Google apparently made a judgment call and decided (absurdly, IMHO) to classify 16:10 as "notlong" (which would explain the behavior of the Xoom and Tab3).
So... it appears that the Nexus 6p (unlike the Note 4) is excluding 168 pixels from the resolution calculation, causing it to fall through the cracks and end up as "notlong" by virtue of having an aspect ratio of 1.66, missing Google's threshold by 0.01.
The moral: as of API 23, "long" and "notlong" are useless as alternate layout selectors, and will remain useless unless Google someday adds a third selector (like "short") that unambiguously matches ONLY (but ALL) devices with 4:3 displays (ie, a device having a 4:3 display should never be classified as "notlong", even if it's using ~128 pixels for the buttons and notification area.)
Answered By - Bitbang3r
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.