Android Emulator Reports 600x1024 MDPI as XLarge?

跟風遠走 提交于 2019-11-30 07:18:41

This seems to be a bug in the documentation. If we look at the actual code that is used to calculate screen size, we can see that a 600x1024 screen at 160 dpi will indeed be considered as xlarge.

Don't take my word for it. The implementation is in WindowManagerService.computeNewConfigurationLocked() (warning for slow JavaScript). The interesting bits are as follows. The screen size in pixels is scaled based on density:

    longSize = (int)(longSize/dm.density);
    shortSize = (int)(shortSize/dm.density);

For a an mdpi (160 dpi) screen, dm.density will be 1.0. For hdpi (240 dpi) it will be 1.5. In our case we have an mdpi screen. So after this code has run, longSize == 1024 and shortSize == 600. Shortly after, we reach this code:

    // What size is this screen screen?
    if (longSize >= 800 && shortSize >= 600) {
        // SVGA or larger screens at medium density are the point
        // at which we consider it to be an extra large screen.
        mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
    } else if ( // ...

which with our values of longSize and shortSize means that mScreenLayout will be assigned Configuration.SCREENLAYOUT_SIZE_XLARGE, in other words that the screen will be considered 'xlarge'. It is interesting to note that if the screen was one pixel smaller on the short side, it would only be considered as 'large'.

So, you are reading the documentation correctly, but as far as I can see, the documentation is wrong and your emulator is just fine.

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