歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> AndroidManifest.xml 詳解 一 譯自——《Beginning Android Games》

AndroidManifest.xml 詳解 一 譯自——《Beginning Android Games》

日期:2017/3/1 11:17:27   编辑:Linux編程

關於Android游戲開發優秀的中文書籍實在是太少,英文的確有很多。

沒辦法,狠下心來學英語,用翻譯工具哪裡不懂點哪裡!

為了提高我的英語水平和記憶強度,我把書上的一些我覺得比較有用的片發到上面,翻譯的不好,勿噴

Beginning Android Games.2011.pdf 下載地址: http://www.linuxidc.com/Linux/2011-09/43951.htm

先來點簡單的:

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.

Copyright © Linux教程網 All Rights Reserved