问题
With Android, you can define different resources for different phone attribute by naming res directories appropriately. I need to be able to support different layouts for 480x800
and 480x854
. I figured I could have one set of resources stored in the layout-hdpi-v4 directory and another in layout-long-hdpi-v4. However, both resolution seem to think that they are long (at least based on the emulator, which I understand may not reflect devices accurately).
Is there another way in which I can distinguish between the two resolutions/aspect ratios?
回答1:
There is a screen size qualifier, though its use is deprecated and recommended to not be used:
layout-800x480
,layout-854x480
Otherwise, it doesn't look like there is a supported way in resource naming that can differentiate the two resolutions, besides using flexible layouts to expand into the extra screen space.
回答2:
If you want to determine the screen size in code, DisplayMetrics will help
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
You can look at the fields widthPixels
and heightPixels
.
However, read too the Best Practices for Screen Independence.
来源:https://stackoverflow.com/questions/1893838/how-does-android-define-a-screen-resolution-as-long