您的位置:首页 > 移动开发 > Android开发

AndroidMainfest.xml详解——<application>

2017-01-11 09:43 309 查看
语法:

<compatible-screens>
<screen android:screenSize=["small" | "normal" | "large" | "xlarge"]
android:screenDensity=["ldpi" | "mdpi" | "hdpi" | "xhdpi"
| "280" | "360" | "420" | "480" | "560" ] />
...
</compatible-screens>


包含于:
<manifest>


说明:

指定应用程序所兼容的屏幕参数。 Manifest 文件中只能出现一次 < compatible-screens > 元素的实例,但该元素中可以包含多个 < screen > 元素。 每个 < screen > 元素定义了一种可兼容的屏幕尺寸-密度组合。

Android 系统并不会读取 Manifest 文件中的 < compatible-screens > 元素(安装和运行时都不会)。 该元素只是作为一种可被外部服务(比如 Google Play )使用的信息,以便更好地了解应用程序对各种屏幕的兼容性,并对用户启用过滤机制。 未在该元素中声明的屏幕参数即表示此应用程序对它不兼容。 这样,外部服务(比如 Google Play )就不会为这些屏幕的设备提供此应用程序。

提醒:通常, 请勿使用本 Manifest 元素 。如果用户设备的屏幕参数未能列出,则这些用户就无法安装该应用程序,因此使用本元素可能会大幅减少潜在的用户群体。仅当程序确实无法在所有屏幕参数下运行时,才作为最后手段使用本元素。 作为替代手段,请按照 支持多种屏幕的指导, 通过对应于各种屏幕尺寸和密度的替代 Layout 和位图,为多种屏幕提供可缩放的支持方案。

如果只是要为应用程序设置一个最小屏幕尺寸,应该使用 < supports-screens > 元素。 比如,应用程序只支持 large 和 xlarge 屏幕的设备,就可以在 < supports-screens > 中元素声明不支持 small 和 normal 屏幕尺寸。 外部服务(比如 Google Play)将据此对应用程序进行过滤。 还可以用 < supports-screens > 元素来声明系统是否可以改变应用程序的大小来适应各种屏幕尺寸。

关于 Google Play 如何利用本元素及其他 Manifest 元素来对应用程序进行过滤,详情请参阅 Google Play 的过滤器文档。

子元素:

< screen >

定义应用程序兼容的一种屏幕参数。

< compatible-screens > 中必须至少包含本元素的一个实例。本元素必须同时包含 android:screenSize 和 android:screenDensity 属性(否则本元素将被忽略)。

属性:

android:screenSize

必填项。定义本条屏幕参数中的屏幕尺寸。

可接受的值:

small

normal

large

xlarge

关于各种屏幕尺寸的更多信息,请参阅支持多种屏幕。

android:screenDensity

必填项。定义本条屏幕参数中的屏幕密度。

可接受的值:

ldpi

mdpi

hdpi

xhdpi

注意: 本属性目前不接受 xxhdpi 值,但可以用 480 来替代,这是最接近 xhdpi 的密度值。

关于屏幕密度的详细信息,请参阅支持多种屏幕。

示例:

如果应用程序不论屏幕密度如何都只能兼容 small 和 normal 大小的屏幕,那就必须指定八种不同的 < screen > 元素, 因为每种屏幕尺寸下都有四种不同的密度配置。每一种组合都必须声明,任何未经声明的尺寸和密度都被视为应用程序不兼容的屏幕参数。 假如应用程序只兼容 small 和 normal 屏幕的话,Manifest 的配置应该类似于这样:

<manifest ... >
...
<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>
<application ... >
...
<application>
</manifest>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: