在Android中

前端之家收集整理的这篇文章主要介绍了在Android中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
美好的一天,我试图在谷歌播放中将屏幕尺寸限制为仅手机(即不是平板电脑).在我找到这个 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图片

我的第一个问题 – 是否可以将屏幕尺寸限制为特定的英寸值,或者我只能使用小型,普通型,大型和Xlarge等标签

在某些时候,我决定通过更新清单将支持英寸大小增加到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英寸的用户仍然无法安装应用程序.

所以我的第二个问题 – 我做错了什么或不明白?

我老老实实地读了关于stackoverflow和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> element不考虑密度:

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属性,但基于density breakpoints的Material Design文档,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>

猜你在找的Android相关文章