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

來源:互聯網
上載者:User

關於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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.