<compatible-screens> 在 Android
<compatible-screens> in Android
美好的一天,我正在尝试将屏幕尺寸限制为 google 游戏中的手机(即不是平板电脑)。在我找到这个 article 之后,我将其添加到我的清单文件中:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
</compatible-screens>
但是现在5.5++英寸手机的用户似乎无法安装我的应用程序。接下来我还找到了这个article和里面的图片:
我的第一个问题 - 是否可以通过特定的英寸值来限制屏幕尺寸,或者我只能使用小号、普通号、大号和超大号等标签?
在某些时候,我决定通过像这样更新清单来将支持英寸大小增加到 7:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<!-- all large size screens -->
<screen android:screenSize="large" android:screenDensity="ldpi" />
<screen android:screenSize="large" android:screenDensity="mdpi" />
<screen android:screenSize="large" android:screenDensity="hdpi" />
<screen android:screenSize="large" android:screenDensity="xhdpi" />
</compatible-screens>
但是5.5寸甚至5.2寸的用户还是无法安装app
所以我的第二个问题 - 我做错了什么或不明白?
老实说,我阅读了所有关于 Whosebug 的类似问题和 android 文档中的文章,但没有找到正确的答案。谢谢
您似乎在尝试将屏幕尺寸限制为仅限手机,而不是平板电脑。很难从你的问题中辨别出来,但无论哪种方式我想我都可以消除困惑。
当您在清单中声明 <compatible-screens>
时,您必须声明 每个 您希望您的应用兼容的屏幕配置:
You must declare each one of these; any combination of size and
density that you do not specify is considered a screen configuration
with which your application is not compatible.
我怀疑你提到的5.5+英寸手机的密度比xhdpi
高;例如 xxhdpi
或 xxxhdpi
。文档中省略了这些密度(因为文档已过时或不完整)但仍然相关;它们记录在 <compatible-screens>
页面上。
因此,如果您希望您的应用与更高密度的设备兼容,则必须在 <compatible-screens>
元素中包含这些密度。但更简单的方法是改用 <supports-screens>
元素。根据文档,<supports-screens>
元素不考虑密度:
Note: Although you can also use the <compatible-screens>
element for the reverse scenario (when your application is not compatible with
smaller screens), it's easier if you instead use the
<supports-screens>
as discussed in the next section, because it
doesn't require you to specify each screen density your application
supports.
有了这个,您只需在清单中指定以下内容:
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="false"
android:xlargeScreens="false"
android:largestWidthLimitDp="840"/>
largestWidthLimitDp
属性应该不是必需的,但根据 Material density breakpoints 的设计文档,840dp 似乎是手机的一个很好的限制。
否则,如果您希望更好地控制您的应用与哪些设备兼容,您仍然可以使用 <compatible-screens>
标签:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<screen android:screenSize="small" android:screenDensity="xxhdpi" />
<screen android:screenSize="small" android:screenDensity="xxxhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
</compatible-screens>
编辑 (2016-12-21)
在 Bryan 建议使用构建工具 25.0.1 后,我的解决方案没有再出现构建错误:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<screen android:screenSize="small" android:screenDensity="xxhdpi" />
<screen android:screenSize="small" android:screenDensity="xxxhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
但是...
对于新版本,某些设备未出现在支持的设备列表中(Google Play 控制台):Google Pixel、Nexus 5x、Google Pixel XL、Nexus 6、Nexus 6P。
这就是为什么我的新解决方案看起来像这样:
<!-- just handsets allowed-->
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" /> <!-- 120 -->
<screen android:screenSize="small" android:screenDensity="mdpi" /> <!-- 160 -->
<screen android:screenSize="small" android:screenDensity="hdpi" /> <!-- 240 -->
<screen android:screenSize="small" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="xhdpi" /> <!-- 320 -->
<screen android:screenSize="small" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="420" /> <!-- Workaround Google Pixel, Nexus 5x -->
<screen android:screenSize="small" android:screenDensity="xxhdpi" /> <!-- 480 -->
<screen android:screenSize="small" android:screenDensity="560" /> <!-- Workaround Google Pixel XL, Nexus 6, Nexus 6P -->
<screen android:screenSize="small" android:screenDensity="xxxhdpi" /> <!-- 640 -->
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" /> <!-- 120 -->
<screen android:screenSize="normal" android:screenDensity="mdpi" /> <!-- 160 -->
<screen android:screenSize="normal" android:screenDensity="hdpi" /> <!-- 240 -->
<screen android:screenSize="normal" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="xhdpi" /> <!-- 320 -->
<screen android:screenSize="normal" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="420" /> <!-- Workaround Google Pixel, Nexus 5x -->
<screen android:screenSize="normal" android:screenDensity="xxhdpi" /> <!-- 480 -->
<screen android:screenSize="normal" android:screenDensity="560" /> <!-- Workaround Google Pixel XL, Nexus 6, Nexus 6P -->
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" /> <!-- 640 -->
</compatible-screens>
旧:
根据 Bryan 的回答,我的清单片段如下所示:
<!-- just handsets allowed-->
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" /> <!-- approximately 120 dpi -->
<screen android:screenSize="small" android:screenDensity="mdpi" /> <!-- approximately 160 dpi -->
<screen android:screenSize="small" android:screenDensity="hdpi" /> <!-- approximately 240 dpi -->
<screen android:screenSize="small" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="xhdpi"/> <!-- approximately 320 dpi -->
<screen android:screenSize="small" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="420" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="480" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="560" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="640" /> <!-- Workaround -->
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" /> <!-- approximately 120 dpi -->
<screen android:screenSize="normal" android:screenDensity="mdpi" /> <!-- approximately 160 dpi -->
<screen android:screenSize="normal" android:screenDensity="hdpi" /> <!-- approximately 240 dpi -->
<screen android:screenSize="normal" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="xhdpi"/> <!-- approximately 320 dpi -->
<screen android:screenSize="normal" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="420" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="480" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="560" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="640" /> <!-- Workaround -->
</compatible-screens>
无法使用 Bryan 的解决方案,因为我遇到编译错误:"AAPT: String types not allowed (at 'screenDensity' with value 'xxxhdpi')"
它适用于(较新的)设备,例如 Google Pixel (2.6 * 160 dp = 416 dp -> 420dp -> explanation:) / Pixel XL (3.5 * 160 dp = 560 dp)或三星 Galaxy S6(4.0 * 160 dp = 640 dp)。
dp 值在此处描述:https://material.io/devices/
我认为这可行,因为我上面提到的设备出现在 Google Play 控制台的 "supported devices" 列表中。
美好的一天,我正在尝试将屏幕尺寸限制为 google 游戏中的手机(即不是平板电脑)。在我找到这个 article 之后,我将其添加到我的清单文件中:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
</compatible-screens>
但是现在5.5++英寸手机的用户似乎无法安装我的应用程序。接下来我还找到了这个article和里面的图片:
我的第一个问题 - 是否可以通过特定的英寸值来限制屏幕尺寸,或者我只能使用小号、普通号、大号和超大号等标签?
在某些时候,我决定通过像这样更新清单来将支持英寸大小增加到 7:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<!-- all large size screens -->
<screen android:screenSize="large" android:screenDensity="ldpi" />
<screen android:screenSize="large" android:screenDensity="mdpi" />
<screen android:screenSize="large" android:screenDensity="hdpi" />
<screen android:screenSize="large" android:screenDensity="xhdpi" />
</compatible-screens>
但是5.5寸甚至5.2寸的用户还是无法安装app
所以我的第二个问题 - 我做错了什么或不明白?
老实说,我阅读了所有关于 Whosebug 的类似问题和 android 文档中的文章,但没有找到正确的答案。谢谢
您似乎在尝试将屏幕尺寸限制为仅限手机,而不是平板电脑。很难从你的问题中辨别出来,但无论哪种方式我想我都可以消除困惑。
当您在清单中声明 <compatible-screens>
时,您必须声明 每个 您希望您的应用兼容的屏幕配置:
You must declare each one of these; any combination of size and density that you do not specify is considered a screen configuration with which your application is not compatible.
我怀疑你提到的5.5+英寸手机的密度比xhdpi
高;例如 xxhdpi
或 xxxhdpi
。文档中省略了这些密度(因为文档已过时或不完整)但仍然相关;它们记录在 <compatible-screens>
页面上。
因此,如果您希望您的应用与更高密度的设备兼容,则必须在 <compatible-screens>
元素中包含这些密度。但更简单的方法是改用 <supports-screens>
元素。根据文档,<supports-screens>
元素不考虑密度:
Note: Although you can also use the
<compatible-screens>
element for the reverse scenario (when your application is not compatible with smaller screens), it's easier if you instead use the<supports-screens>
as discussed in the next section, because it doesn't require you to specify each screen density your application supports.
有了这个,您只需在清单中指定以下内容:
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="false"
android:xlargeScreens="false"
android:largestWidthLimitDp="840"/>
largestWidthLimitDp
属性应该不是必需的,但根据 Material density breakpoints 的设计文档,840dp 似乎是手机的一个很好的限制。
否则,如果您希望更好地控制您的应用与哪些设备兼容,您仍然可以使用 <compatible-screens>
标签:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<screen android:screenSize="small" android:screenDensity="xxhdpi" />
<screen android:screenSize="small" android:screenDensity="xxxhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
</compatible-screens>
编辑 (2016-12-21)
在 Bryan 建议使用构建工具 25.0.1 后,我的解决方案没有再出现构建错误:
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<screen android:screenSize="small" android:screenDensity="xxhdpi" />
<screen android:screenSize="small" android:screenDensity="xxxhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxhdpi" />
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" />
但是... 对于新版本,某些设备未出现在支持的设备列表中(Google Play 控制台):Google Pixel、Nexus 5x、Google Pixel XL、Nexus 6、Nexus 6P。
这就是为什么我的新解决方案看起来像这样:
<!-- just handsets allowed-->
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" /> <!-- 120 -->
<screen android:screenSize="small" android:screenDensity="mdpi" /> <!-- 160 -->
<screen android:screenSize="small" android:screenDensity="hdpi" /> <!-- 240 -->
<screen android:screenSize="small" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="xhdpi" /> <!-- 320 -->
<screen android:screenSize="small" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="420" /> <!-- Workaround Google Pixel, Nexus 5x -->
<screen android:screenSize="small" android:screenDensity="xxhdpi" /> <!-- 480 -->
<screen android:screenSize="small" android:screenDensity="560" /> <!-- Workaround Google Pixel XL, Nexus 6, Nexus 6P -->
<screen android:screenSize="small" android:screenDensity="xxxhdpi" /> <!-- 640 -->
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" /> <!-- 120 -->
<screen android:screenSize="normal" android:screenDensity="mdpi" /> <!-- 160 -->
<screen android:screenSize="normal" android:screenDensity="hdpi" /> <!-- 240 -->
<screen android:screenSize="normal" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="xhdpi" /> <!-- 320 -->
<screen android:screenSize="normal" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="420" /> <!-- Workaround Google Pixel, Nexus 5x -->
<screen android:screenSize="normal" android:screenDensity="xxhdpi" /> <!-- 480 -->
<screen android:screenSize="normal" android:screenDensity="560" /> <!-- Workaround Google Pixel XL, Nexus 6, Nexus 6P -->
<screen android:screenSize="normal" android:screenDensity="xxxhdpi" /> <!-- 640 -->
</compatible-screens>
旧:
根据 Bryan 的回答,我的清单片段如下所示:
<!-- just handsets allowed-->
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" /> <!-- approximately 120 dpi -->
<screen android:screenSize="small" android:screenDensity="mdpi" /> <!-- approximately 160 dpi -->
<screen android:screenSize="small" android:screenDensity="hdpi" /> <!-- approximately 240 dpi -->
<screen android:screenSize="small" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="xhdpi"/> <!-- approximately 320 dpi -->
<screen android:screenSize="small" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="420" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="480" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="560" /> <!-- Workaround -->
<screen android:screenSize="small" android:screenDensity="640" /> <!-- Workaround -->
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" /> <!-- approximately 120 dpi -->
<screen android:screenSize="normal" android:screenDensity="mdpi" /> <!-- approximately 160 dpi -->
<screen android:screenSize="normal" android:screenDensity="hdpi" /> <!-- approximately 240 dpi -->
<screen android:screenSize="normal" android:screenDensity="280" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="xhdpi"/> <!-- approximately 320 dpi -->
<screen android:screenSize="normal" android:screenDensity="360" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="420" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="480" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="560" /> <!-- Workaround -->
<screen android:screenSize="normal" android:screenDensity="640" /> <!-- Workaround -->
</compatible-screens>
无法使用 Bryan 的解决方案,因为我遇到编译错误:"AAPT: String types not allowed (at 'screenDensity' with value 'xxxhdpi')"
它适用于(较新的)设备,例如 Google Pixel (2.6 * 160 dp = 416 dp -> 420dp -> explanation:) / Pixel XL (3.5 * 160 dp = 560 dp)或三星 Galaxy S6(4.0 * 160 dp = 640 dp)。 dp 值在此处描述:https://material.io/devices/
我认为这可行,因为我上面提到的设备出现在 Google Play 控制台的 "supported devices" 列表中。