Android 入門 (2)

The Android Project Structure

前情提要

  • 為什麼 1/30 前只有一個人幫我填表單拉QQ
  • 這份簡報稍微枯燥,算是複習前面我說過的內容,但沒放到簡報上的東西

Get Started!

The Android Project View

android project structure

1. Android Manifest file

  • An AndroidManifest.xml is required for every Android app.
    • It uses XML to define specific application information.
  • The Information
    • Launch icon
    • Application name
    • Application style
    • Filters of intents
    • Hardware requirements
    • etc...

1. Android Manifest file

            
            
            
              
                 
                  
                     
                    
                  
                
              
            
            
          

2. Activity

  • An app is made up of one or more Activities.
  • Each Activity is represented by a visual interface to the user, called layout, along with source code.
    • Java class: determining the behavior of the activity, files located in app/java.
    • Layout: determining the view of the activity, files located in res/layout.

3. Resources

developer.android.com

3.1 Drawable

  • Drawable resources are image files.
  • The most common drawable resource used is .png file.
  • R.drawable.xxx    @drawable/xxx
  • Android runs on a variety of devices, so we use dpi rather than px.
    • px: Pixel
    • dp: Density-independent pixel, that is, one physical pixel on a 160-dpi screen
    • dpi: Dots Per Inch
    • \[px = dp \times(dpi \div160)\]

3.1 Drawable

  • A set of six generalized densities:
    • ldpi (low) ~120dpi / QVGA
    • mdpi (medium) ~160dpi / HVGA (x1.0)
    • hdpi (high) ~240dpi / WVGA, FWVGA (x1.5)
    • xhdpi (extra-high) ~320dpi / 720P (x2.0)
    • xxhdpi (extra-extra-high) ~480dpi / 1080p (x2.6, x3.0)
    • xxxhdpi (extra-extra-extra-high) ~640dpi / 4K (x3.5, x4.0)
  • Device Metrics: https://material.io/devices/

3.2 Layout

  • When a layout appears on the screen, it is managed by an Activity.
  • Two ways to define interface controls:
    • Declare in XML.
    • Created programmatically at runtime.
  • It is not recommanded to instantiate elements at runtime due to organization and maintainability!
  • R.layout.xxx

3.3 Values

  • It can be:
    • Strings: R.string.xxx    @string/xxx
    • Colors: R.color.xxx    @color/xxx
    • Styles: R.style.xxx    @style/xxx
    • etc...
  • Android encourages the separation of functionality and resources.
    • Keeping values separate from functions makes code be more clear and easy to manage.

3.3 Mipmap

  • A directory which contains Launcher icon (a.k.a. app icon)
  • @mipmap/xxx

3.4 Anim, Animator

  • anim, animator is not necessory in the project.
  • You can define Animation here.

4. Gradle Scripts

  • The Gradle Scripts directory stores the application’s build files.
          
            android {
              compileSdkVersion 26
              defaultConfig {
                applicationId "tw.kaiyeee.android.firstapp"
                minSdkVersion 21
                targetSdkVersion 26
                versionCode 1
                versionName "1.0"
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
              }
              buildTypes {
                release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
              }
          }