20.11.2016 Views

ANDROID APP

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ไฟล์ต่างๆ ที่ผู้พัฒนาจะต้องสร้างขึ้นเองมีดังนี้<br />

m โฟลเดอร์ src/ จะเก็บไฟล์จาวาแพ็คเกจที่ผู้พัฒนาสร้างขึ้น หรืออิมพอร์ตเข้ามาใช้งาน<br />

โดยในแต่ละแพ็คเกจสามารถมีไฟล์จาวาได้หลายๆ ไฟล์ แต่ละไฟล์จะแทนคลาสแต่ละ<br />

คลาส<br />

m โฟลเดอร์ res/layout/ จะเก็บไฟล์ XML ที่กำหนดค่าเลย์เอาต์ของแต่ละจอภาพ<br />

m โฟลเดอร์ res/values/ จะเก็บไฟล์ XML ที่กำหนดค่าอ้างอิงต่างๆ เพื่อใช้งานในไฟล์อื่นๆ<br />

m โฟลเดอร์ res/drawable-hdpi/ , res/drawable-mdpi และ res/drawable-ldpi จะ<br />

เก็บไฟล์รูปภาพที่ใช้ในแอพ ซึ่งจะแยกออกเป็นความละเอียดสูง กลาง และต่ำ<br />

m โฟลเดอร์ assets/ จะเก็บไฟล์ต่างๆ ที่ไม่ใช่มีเดียไฟล์ (Media File) ที่ใช้ในแอพพลิเคชั่น<br />

m AndroidManifest.xml เป็นไฟล์ที่เก็บข้อมูลของโปรเจ็กต์<br />

ส่วนไฟล์ที่ระบบสร้างขึ้นมาให้อัตโนมัติมีดังนี้<br />

m โฟลเดอร์ gen/ จะเก็บชุดคำสั่งที่ระบบสร้างขึ้นอัตโนมัติ รวมทั้งสร้างไฟล์ R.java ด้วย<br />

m ไฟล์ default.properties จะเก็บค่าต่างๆ ของโปรเจ็กต์<br />

ในส่วนของทรัพยากรหรือรีซอร์ส (Resource) ของแอพจะประกอบไปด้วยไฟล์ XML ซึ่งจะเก็บ<br />

ข้อมูลของเลย์เอาต์ โดยเป็นข้อมูลประเภทข้อความ, ลาเบลของอีลีเมนต์ UI และไฟล์ชนิดอื่นๆ เช่น<br />

ไฟล์ข้อมูลภาพหรือเสียง ในระหว่างที่ทำการคอมไพล์แอพนั้น ข้อมูลเหล่านี้จะถูกอ้างอิงและรวมเข้า<br />

อัตโนมัติร่วมกับคลาส R.java ซึ่งเครื่องมือชื่อ Android Asset Packaging Tool (aapt) จะสร้างไฟล์<br />

นี้ขึ้นมา โดยด้านล่างนี้คือชุดคำสั่งที่เกิดขึ้นหลังจากการสร้างโปรเจ็กต์<br />

ชุดคำสั่งที่ 2.4 gen/com/cookbook/simple_activity/R.java<br />

/* AUTO-GENERATED FILE. DO NOT MODIFY.<br />

*<br />

* This class was automatically generated by the<br />

* aapt tool from the resource data it found. It<br />

* should not be modified by hand.<br />

*/<br />

package com.cookbook.simple_activity;<br />

public final class R {<br />

public static final class attr {<br />

}<br />

public static final class drawable {<br />

public static final int icon=0x7f020000;<br />

}<br />

public static final class layout {<br />

public static final int main=0x7f030000;<br />

}<br />

public static final class string {<br />

public static final int app_name=0x7f040001;<br />

public static final int hello=0x7f040000;<br />

}<br />

}<br />

โครงสร้างการทำางานของแอพแอนดรอยด์<br />

27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!