Notice
Recent Posts
Recent Comments
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Adagio non molto

[Android] Hello World 이해하기 기초 본문

Study/JAVA

[Android] Hello World 이해하기 기초

마르카토* 2011. 12. 13. 23:50
자바를 얼추 공부하고 안드로이드를 들어가자마자 위협하는 XML !! ㅡㅜ
XML은 따로 공부하지 않고 그저 이해하기로 결정...

일단 기본적으로 Hello World 소스(?)는

package exam.adroidfirst;

import android.app.Activity;
import android.os.Bundle;

public class AndroidFirstActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }


중요한건 setContentView !
이 메소드의 기능은 리소스를 읽고 레이아웃에 포함된 뷰를 생성하여 액티비티에 채우는 것
즉, 위에서는 R.layout.main이 리소스역할을 하는 것. 

그래서 main.xml 파일을 들어가면 레이아웃 구조를 볼 수 있다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

xml 버전과 인코딩 방식이 맨 윗줄에 있고...
LinearLayout을 설정하고, 글을 출력하는 TextView가 있다.
그 중 굵은 문장 즉, 네임스페이스 android를 달고 있는 text속성이 있다.
굵은 문장은 "@string/hello"를 출력하라 !
hello가 무엇인지 보기 위해 string.xml로 넘어가면.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, AndroidFirstActivity!</string>
    <string name="app_name">AndroidFirst</string>

</resources>

hello는  Hello World, AndroidFirstActivity! 라고 되어있다.

결국 프로그램을 실행하면 저 문장이 출력되는 것이다 !!



에휴 ㅜ 겨우 이해한 느낌... ㄷ 

 
Comments