1. 화면 구조



• 컨텐트 영역 (id/content)
- 액티비티의 레이아웃을 담고 있는 뷰

2. 자바코드를 이용한 화면 구성
• 레이아웃 및 Child View의 인스턴스 생성
- LinearLayout
- TextView
• 각 View의 속성, 레이아웃 속성 지정
- LinearLayout
orientation
layout_height, layout_width
- TextView
text
layout_height, layout_width
package com.androidhuman.HelloAndroid;
import! android.app.Activity;
import! android.os.Bundle;
import! android.view.ViewGroup;
import! android.widget.LinearLayout;
import! android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout root = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT,
0.0F);
root.setLayoutParams(params);
root.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this);
tv.setText(R.string.hello);
LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0.0F);
tv.setLayoutParams(tvParams);
root.addView(tv);
setContentView(root);
}
}
• LinearLayout 인스턴스 생성

Context (Activity)
정보를 넘겨줌
• 레이아웃 속성 객체 생성

• 레이아웃 속성 적용
• 뷰 배치 방향 설정

• TextView 인스턴스 생성

Context (Activity)
정보를 넘겨줌
• 레이아웃 속성 객체 생성
• TextView 속성 적용
• LinearLayout에 TextView 추가
• LinearLayout을 액티비티의 화면으로 설정

• 완성된 액티비티
- 레이아웃을 이용해 구성한 경우와 결과가 동일
