How does Android define a screen resolution as long?

北城以北 提交于 2019-12-19 09:46:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!