본문 바로가기

KOSTA교육/안드로이드 프로그래밍

안드로이드 교육 1일차


[환경설정]
(1). java 6 : jdk + jre
    - path :
    - classpath :
    - javaVM;(HotStopVM, JVM, CVM, KVM, Card-VM)

(2). eclipse (sdk galileo version)
    - 다운로드 URL : http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR2/eclipse-java-galileo-SR2-win32.zip
    -  API  : C:\android_9\android-sdk-windows\docs\reference\packages.html
                 http://developer.android.com/reference/packages.html

(3). plugin :  DDMS,ADT
    - help>install new softeware... <add> 버튼 클릭
    -  플러그인 설치 주소 : name :  Android Plugin
                                    location : https://dl-ssl.google.com/android/eclipse

(4). android sdk
    - 다운로드 URL : http://developer.android.com/sdk/download.html?v=android-sdk_r05-windows.zip
    - window>preperence >Android
    - SDK Location : C:\android_9\android-sdk-windows(안드로이를 압축을 푼 폴더를 지정 해 주면된다.)
    - window > Android SDK and AVD Manager > Availavle Packages > Site,Package and Archives에 Install Selected
      전체 선택을 하여 전체 설치를 해준다. 설치시간은( 2시간정도...네트워크에따라 다름)

(5). HelloAndroid 만들기...
   1. window > Android SDK and AVD Manager >  New 버튼 클릭    
      -   Name : android-AVD
      -   Target : Android 2.1 - API  Level 7
      -   size : 32~256
      -   "Create AVD" 버튼을 클릭하여 생성을 한다.
   2. New > Android Project 생성
       - HelloAndroid
   3. 개발자 측면에서의 App의 구성요소
       - src : *.java , *.aidl
       - gen : R.java
       - Android 21. : android.jar(core.jar)
       - assets : html, txt, ttf,....
       - res (   drawable : 이미지저장 위치 [ image : PNG , jpg, gif]     
                   layout : 화면의 구성 XML
                   values : xml(String.xml, Colors.xml, Style.xml, Dimen.xml...)
                )
        - AndroidManifest.xml : App의 전반적인 배치(delploy)정보 - Activity, Intenet, perssion, version, 
    
 ※ LifeCyle : 상태[구체적 환경], 메소드{by 쓰레드 or System(android)}
                     [ Sevlet, Applet, MIDIet, Clet, JIet, JIet, Xlet,...., Thread ]

 ※ Instance : 라면...? 처럼 찍어 낼 수 있는 메모리 상에 상주된 객체(Everthing)
 
 ※ final : 수정제한 , static : 소유제한자 (클래스에 소속된 -  모든 객체에게 공유)
    주체 : 클래스 / 객체
    대상 : 변수(속성,Field) / 메소드
             데이터(속성값,값)
    class C {
         static final int I = 10; //static을 쓰므로 클래스에 상속되므로 메모리상에 하나만 존재하게해서 효율성을 올린다.
    }     


[소스 분석]
HelloAndroid.java[/HelloAndroid/src/com/base/HelloAndroid.java]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package com.base;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
 
 /**
  * main()이 없다는 것은 인입점이 없다는  것인다.
  * 곳 그것은 LifeCyle 을 자체 적으로 관리 하겠다는 것이다.
  * LifeCyle : 상태[구체적 환경], 메소드{by 쓰레드 or System(android)}
                     [ Sevlet, Applet, MIDIet, Clet, Jlet, Jlet, Xlet,...., Thread ]
  */
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        //savedInstanceState : 메모리에 로딩된 객체 상태 가지고 있는
        super.onCreate(savedInstanceState);
        //super : 부모의 생성자 호출 - @Override 되기 전의 메소드를  부모 객체 호출
        this.setContentView(R.layout.main);
    }
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

R.java[/HelloAndroid/gen/com/base/R.java]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package com.base;
public final class R {
 //클래스 속의 내부 클래스
    public static final class attr {
    }
    // 객체는 new로 접근을 하지만 클래스는 클래스 이름으로 바로 접근이 가능하다.
    public static final class drawable {
        public static final int icon=0x7f020000; //상수변수에 int 주소값을  공유해서 메모리상의 res를 효율을 높인다.
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

main.xml[/HelloAndroid/res/layout/main.xml]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>
 : LinearLayout부모 를 상속 받는다.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

strings.xml[/HelloAndroid/res/values/strings.xml]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">안녕, 보영이야!</string>
    <string name="app_name">제목이야</string>
</resources>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

AndroidManifest.xml[/HelloAndroid/AndroidManifest.xml]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.base"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 ※ 에뮬레이터에 뛰어진 구조를 보여준다.
C:\android_9\android-sdk-windows\tools\hierarchyviewer.bat

(6) UI 디자인
        java.lang.Object
          ↳ android.view.View : 컴포넌트
     ↳ android.view.ViewGroup :
       ↳ android.widget.LinearLayout

   1.  ViewGroup를 공부하자 : Layout(android.widget 패키지에 있다) - ViewGroup의 자식들이다.
        - LinearLayout, FrameLayout, RelativeLayout, AbsoluteLayout,TableLayout
   2. View를 공부하자
       - Button, TextView,....


첨부파일 소스