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 {
@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 인스턴스 생성
댓글 없음:
댓글 쓰기