Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 工程師入門筆記(一):環境、專案結構與基礎控制項

編輯:關於 Android 開發

Android 工程師入門筆記(一):環境、專案結構與基礎控制項

踏入 Android 開發的第一步,往往從熟悉開發環境與專案結構開始。本文整理了入門階段最需要掌握的幾個重點,適合剛起步的新手快速上手。

一、環境搭建

環境安裝部分各家教學已相當完整,此處不再贅述,直接進入正題。

二、專案結構

在 Android Studio 中,一個專案(Project)等同於一個 Module,理解各資料夾的職責是入門關鍵:

res:存放所有應用資源,基本上決定了 APK 的最終大小。
java:存放 Java 原始碼。
manifests:清單檔,記錄所有配置,也是每次執行的第一個存取入口。

res 底下又細分為:drawable(圖片資源)、layout(版面配置)、menu(選單專用配置)、mipmap(自 Android 4.3 起 Google 強烈建議用於放置圖示,可提升渲染速度與畫質、降低 GPU 壓力)、values(字串、主題、顏色、樣式)。

三、輸入與顯示文字

常用控制項:
TextView:顯示文字的核取方塊式控制項。
EditText:可輸入文字的控制項,額外多了 hint(輸入提示)與 inputType(輸入類型)兩個屬性。

常見屬性包含 android:id、layout_width、layout_height、text、textSize、textColor、background 等。

四、實作範例

在 layout 的 main.xml 中,透過 TextView 與 EditText 即可完成一個簡單的姓名輸入介面:

<!-- wrap_content: 包含實際內容; match_parent: 鋪滿父容器 -->
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="姓名:"
android:textSize="28sp"
android:textColor="#000000" />

<EditText
android:hint="請輸入你的姓名"
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="match_parent" />

掌握 these 基礎後,就能進一步組合出更豐富的圖形介面。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved