AndroidManifest.xml 详解 (一) 之<manifest>——译自《Beginning Android Games》

来源:互联网 发布:数据烟囱 是什么意思 编辑:程序博客网 时间:2024/04/28 16:01

关于android游戏开发优秀的中文书籍实在是太少,英文的确有很多。

 

没办法,狠下心来学英语,用翻译工具哪里不懂点哪里!

 

为了提高我的英语水平和记忆强度,我把书上的一些我觉得比较有用的片发到上面,翻译的不好,勿喷

 

先来点简单的:

AndroidManifest.xml 之 <manifest> 元素

<manifest> 标签是AndroidManifest.xml 的根节点,这有一个基本的例子:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.helloworld"
      android:versionCode="1"
      android:versionName="1.0"
      android:installLocation="preferExternal"> 
...
</manifest>

可能以前你用过XML, 可能对于第一行已经很熟悉了,<manifest>标签指定了一个我们可以在其他 manifest 文件都可以看到的android 命名空间。

package属性定义了我们应用中的root包。 在将来我们会创建各种类到相对于这个包名的包中。

 

versionCode 和 versionName 属性 指定了我们的应用版本的两种形式。

versionCode是一个整数,我们必须在每个更新版本发布的时候加1,这样Android Market才能追踪到应用版本。

versionName是用户可见的版本号,可以是任意字符串(比如说1.0, 2.0...)

 

installLocation 属性用来制定应用在SD卡上的安装的路径(只有在android2.2版本及以上有用),如果有可能尽量把andorid2.2及以上的应用安装在内部储存设备中。

 

在manifest里面所有的元素属性通常都以android作为前缀

 

在<manifest>元素里面,定义了应用的组件,权限,硬件配置和支持的android版本。

 

下面一个元素是<application>。今天先到这里~

附上原文:

The <manifest> Element
The <manifest> tag is the root element of an AndroidManifest.xml file. Here’s a basic
example:
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
      package="com.helloworld"
      android:versionCode="1"
      android:versionName="1.0"
      android:installLocation="preferExternal"> 
...
</manifest>


Assuming you have worked with XML before, you should be familiar with the first line.
The <manifest> tag specifies a namespace called android, which is used throughout the
rest of the manifest file. The package attribute defines the root package name of our
application. Later on, we’ll reference specific classes of our application relative to this
package name. 


The versionCode and versionName attributes specify the version of our application in two
forms. The versionCode is an integer we have to increment each time we publish a new
version of our application. It is used by the Android Market to track our application’s
version. The versionName is displayed to users of the Android Market when they
browses our application. We can use any string we like here. 

 
The installLocation attribute is only available to us if we set the build target of our
Android project in Eclipse to Android 2.2 or newer. It specifies where our application
should be installed. The string preferExternal tells the system that we’d like our
application to be installed to the SD card. This will only work on Android 2.2 or newer,
and is ignored by all earlier Android applications. On Android 2.2 or newer the
application will always get installed to the internal storage if possible.


All attributes of the XML elements in a manifest file are generally prefixed with the
android namespace, as shown previously. For brevity, I will not specify the namespace
in the following sections when talking about a specific attribute. 
Inside the <manifest> element, we then define the application’s components,
permissions, hardware profiles, and supported Android versions.

原创粉丝点击