Android模拟器报告600x1024 MDPI为XLARGE?模拟器、报告、Android、XLARGE

2023-09-05 09:22:40 作者:独孤漠

我目前正在测试用于与即将推出的亚马逊Kindle Fire平板电脑兼容现有的应用程序。他们说,设置仿真器为600x1024和液晶密度为169(https://developer.amazon.com/help/faq.html?ref_=pe_132830_21362890#KindleFire虽然在电子邮件,他们说160,而不是169),它应该作为报出大,而不是XLARGE(这我从与他们的支持团队在那里我抱怨它不工作一个来回电子邮件交流)。

谷歌似乎在他们列出本决议MDPI为大(http://developer.android.com/guide/practices/screens_support.html#testing).但是,只要我有一个布局XLARGE文件夹中伴随着布局大,模拟器总是加载XLARGE如果我更改LCD密度,以类似240,它装载大,而不是 XLARGE,但不应该是正确的,我很担心,这意味着它不会在最终的设备上运行。要进行测试,我花了的API-10样品多分辨率,并创作了一系列上述布局的文件夹,每一次它装XLARGE,如果它在那里,将装载大,如果没有一个XLARGE。

所以,我的问题是,如果我读文档正确,或者如果我模拟器不知怎么搞砸的人在亚马逊的坚持,应该报告为大,而如果这是真的,那将永远载入 XLARGE吧?

下面是我在清单中的例子多分辨率,我修改,以测试这一点:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  包=com.example.android.multires
  安卓版code =1
  机器人:VERSIONNAME =1.0>

  <使用,许可
    机器人:名称=android.permission.INTERNET对/>

  <应用
    机器人:图标=@可绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME>

    <活动
      机器人:多分辨率NAME =
      机器人:标签=@字符串/ APP_NAME>
      <意向滤光器>
        <作用
          机器人:名称=android.intent.action.MAIN/>
        <类别
          机器人:名称=android.intent.category.LAUNCHER/>
      &所述; /意图滤光器>
    < /活性GT;
  < /用途>

  <使用-SDK安卓的minSdkVersion =4/>

  <支持屏安卓anyDensity =真
                    机器人:xlargeScreens =真
                    机器人:largeScreens =真
                    机器人:normalScreens =真
                    机器人:smallScreens =真/>

< /舱单>
 

解决方案 谷歌推送Android 11开发者预览版第二版 改进面部解锁方式并加入屏幕录制功能

这似乎是文件中的错误。如果我们看一下用来计算屏幕尺寸的实际code,我们可以看到,一个600x1024屏幕在160 dpi的的确被视为XLARGE。

不要把我的话。实施是在WindowManagerService.computeNewConfigurationLocked() (警告缓慢的JavaScript)。有趣的位如下所示。在像素的屏幕尺寸是基于密度来衡量的:

  LONGSIZE =(INT)(LONGSIZE / dm.density);
    shortSize =(INT)(shortSize / dm.density);
 

对于一个MDPI(160 dpi)的屏幕,dm.density为1.0。对于华电国际(240 DPI),它是1.5。在我们的例子中,我们有一个MDPI屏幕。因此,在此之后code已经用完, LONGSIZE == 1024 shortSize == 600 。不久后,我们到达这个code:

  //这有多大的屏幕画面?
    如果(LONGSIZE> = 800安培;&安培; shortSize> = 600){
        //在中密度SVGA或更大的屏幕被点
        //在此,我们认为它是一个额外的大屏幕。
        mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE;
    }否则,如果(// ...
 

这跟我们 LONGSIZE shortSize 表示 mScreenLayout 将被分配 Configuration.SCREENLAYOUT_SIZE_XLARGE ,在屏幕上会被视为XLARGE等字样。有趣的是,要注意,如果在屏幕是一个象素较小的短边,这将仅被视为大。

那么,你是正确的阅读文档,但就我所看到的,文件是错误的,你的模拟器还是蛮好的。

I am currently trying to test an existing application for compatibility with the soon to be released Amazon Kindle Fire tablet. They say to set the emulator at 600x1024 and LCD Density to 169 (https://developer.amazon.com/help/faq.html?ref_=pe_132830_21362890#KindleFire although in email they said 160 instead of 169) and that it should report out as being "large" and not "xlarge" (this I have from a back and forth email exchange with their support team where I'm complaining it does not work).

Google seems to support this as being true in their section on testing for multiple screen sizes when they list this resolution and MDPI as being "large" (http://developer.android.com/guide/practices/screens_support.html#testing). However, anytime I include a "layout-xlarge" folder along with the "layout-large", the emulator is always loading the "xlarge". If I change the LCD Density to something like 240, it loads "large" instead of "xlarge", but that is not supposed to be correct and I'm worried that means it won't work on the final device. To test this, I took the API-10 sample of "Multi-Res" and created a series of layout folders described above and every time it loaded "xlarge" if it was there and would load "large" if there was not an "xlarge".

So, my question is if I'm reading the documentation correctly or if my emulator is somehow messed up as the folks at Amazon are insisting it should be reporting as "large", which if that were true it would never load "xlarge" right?

Here is what I have in the manifest in the example Multi-Res that I modified to test this:

<?xml version="1.0" encoding="utf-8"?>
<manifest
  xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.android.multires"
  android:versionCode="1"
  android:versionName="1.0">

  <uses-permission
    android:name="android.permission.INTERNET"/>

  <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name">

    <activity
      android:name=".MultiRes"
      android:label="@string/app_name">
      <intent-filter>
        <action
          android:name="android.intent.action.MAIN"/>
        <category
          android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
  </application>

  <uses-sdk android:minSdkVersion="4" />

  <supports-screens android:anyDensity="true"
                    android:xlargeScreens="true"
                    android:largeScreens="true"
                    android:normalScreens="true"
                    android:smallScreens="true" />

</manifest>

解决方案

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.