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

來源:互聯網
上載者:User

 

接上篇~

 

<application>元素

我們以以下這個例子來討論<application>元素

 

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
...
</application>

 

    現在看起來可能有點奇怪,@drawable/icon 和 @string/app_name 是什麼呢?當我們開發了一個基於android的應用,我們通常用許多XML去定義一些特殊的資源。

我們必須要有能區分這些定義在XML中的資源(比如說圖片,國際化字串)。這些資源儲存在res/檔案夾下。

    我們用先前的標記去索引這些資源。 @指定了我們希望索引在別處的資源。接下來的字串標記了我們希望索引到的資源類別,並直接映射到res/目錄下

資源所在的檔案夾或者檔案中。最後的部分指定了資源的名字,比如在之前的例子中的圖片名字叫icon,字串的名字叫app_name。這裡的圖片名字是一個真實的檔案名稱,我們

可以在res/drawable/檔案夾下找到。字串 app_name定義在res/values/strings.xml檔案裡。這個檔案裡定義的所有字串將被用在應用中。

NOTE:

    在android中,資源處理是一個非常靈活的,同時也是非常複雜的東西。在這本書中,我出於2個原因去放棄使用這種方法。

    1、在遊戲開發中,這種處理方法對於需要完全控制資源的我們有過度(殺傷力)。

    2、Android有一個修改在res/檔案夾下資源的習慣,特別是圖片(它稱為drawables),而這些

修改又不是我們在遊戲開發中所希望的。

    在遊戲開發中我唯一建議使用android的資源系統是——國際化字串。

    我們通常在遊戲開發中使用assets/檔案夾來儲存資源,在此檔案夾下我們的資源將不會被做任何修改。

 

    <application>元素的意義想必現在已經非常清楚了。

    icon屬性指定了用與作為應用表徵圖的圖片,圖片儲存於 res/drawable/檔案夾下,這個表徵圖將在android market中和

我們的裝置上顯示,它也所有在 <application>元素中定義的activity的預設表徵圖

    debuggable屬性指定了我們的應用是否能夠調試,在開發中,我們通常把它設定為true。當你把應用發布到android market上的時候,就需要把它設定為false。

如果你不把他設定為true,你將不能在Eclipse上調試此應用。

     我們僅僅討論了一小部分你可以指定的<application>元素的子集及其屬性,然而這些子集和屬性以及足夠我們開發遊戲所用,如果你希望瞭解更多的內容,你可以在

Android開發官方文檔上找到全部的內容。

    <application>元素包涵了所有應用組件的精確定義(包涵activity,services)而且也包涵了任何我們添加的庫。

 

 

 

下一個是<activity>~

另附上原文: 

 

The <application> Element
As in the case of the <manifest> element, let’s discuss the <application> element in the
form of an example:

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
...
</application>

 

    Now this looks a little bit strange. What’s up with the @drawable/icon and
@string/app_name strings? When developing a standard Android application, we usually
write a lot of XML files, each defining a specific portion of our application. To be able to
fully define those portions, we must also be able to reference resources that are not
defined in the XML file, such as images or internationalized strings. These resources are
located in subfolders of the res/ folder, as discussed in Chapter 2 when we dissected
the Hello World project in Eclipse. 

 

    To reference resources, we use the preceding notation. The @ specifies that we want to
reference a resource defined elsewhere. The following string identifies the type of the
resource we want to reference, which directly maps to one of the folders or files in the
res/ directory. The final part specifies the name of the resource—in the preceding case
an image called icon and a string called app_name. In the case of the image, it’s the
actual filename we specify, as found in the res/drawable/ folder. Note that the image
name does not have a suffix like .png or .jpg. Android will infer that automatically based
on what’s in the res/drawable/ folder. The app_name string is defined in the
res/values/strings.xml file, a file where all the strings used by the application will be
stored. The name of the string was defined in the strings.xml file.

 

    NOTE: Resource handling on Android is an extremely flexible but also complex thing. For this
book, I decided to skip most of it for two reasons: it’s utter overkill for game development and we
want to have full control over our resources. Android has the habit of modifying resources placed
in the res/ folder, especially images (called drawables). That’s something we do not want asgame developers. The only thing I‘d suggest using the Android resource system for in game

    development is internationalizing strings. We won’t get into that in this book; instead we’ll use
the more game development–friendly assets/ folder, which leaves our resources untouched
and allows us to specify our own folder hierarchy.

    The meaning of the attributes of the <application> element should become a bit clearer
now. The icon attribute specifies the image from the res/drawable/ folder to be used as
an icon for the application. This icon will be displayed in the Android Market as well as in
the application launcher on the device. It is also the default icon for all the activities we
define within the <application> element.

    The label attribute specifies the string being displayed for our application in the
application launcher. In the preceding example, this references a string in the
res/values/string.xml file, which is what we specified when we created the Android
project in Eclipse. We could also set this to a raw string, such as My Super Awesome
Game. The label is also the default label for all the activities we define in the
<application> element. The label will be shown in their title bar of our application.
The debuggable attribute specifies whether our application can be debugged or not. For
development, we should usually set this to true. When you deploy your application to
the market, just switch it to false. If you don’t set this to true, you won’t be able to
debug the application in Eclipse.

 

    We have only discussed a very small subset of the attributes you can specify for the
<application> element. However, these are sufficient for our game development needs.
If you want to know more, you can find the full documentation on the Android
Developers site.

    The <application> element contains the definitions of all the application components,
including activities and services, as well as any additional libraries used.  

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.