Android/2012.04월 강좌

2일차 기본

Bohemian life 2012. 4. 27. 11:42
package com.sogangori; 

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class HelloWorldActivity extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //set 셋팅해라 what: ContentView how:R.layout.main
       // this.setContentView(R.layout.main);
        
        // 뷰 타입의 객체를 만들어서 화면에 붙이기
        TextView tv=new TextView(this);
        tv.setText("Friday ");
        // tv의 글자 크기 셋팅 해라 30.55f 로
        tv.setTextSize(30.55f);
        // tv의 글자 컬러 셋팅 해라 Color.RED 로
        LayoutParams params=new LayoutParams(100,100);
        tv.setLayoutParams(params);
        
        // tv의 배경 컬러 셋팅 해라 
        tv.setTextColor(Color.GREEN);
        
       // setContentView(tv);
        
        //버튼(Button) 만들어서/글자를 setting/글자컬러set
        //글자크기set/배경컬러set/화면에 띄우기
        Button button=new Button(this);
        button.setLayoutParams(params);
        button.setText(R.string.myname); // 리소스 사용
        button.setTextColor(Color.BLUE);
        button.setTextSize(10);
        button.setBackgroundColor(Color.RED);
       // setContentView(button);
        
        // 자원 resource 활용
        
        // 3.ImageView 이미지를 넣을 수 있는 뷰
        // 파일이름 a-z, 0-9 . - _ 만 허용
        // 파일이름은 소문자로 시작
        
        ImageView imageView=new ImageView(this);
        // setting Image  how: resource (리소스)
        imageView.setImageResource(R.drawable.dolly);
        imageView.setLayoutParams(params);
       // setContentView(imageView);
        
        //방향 선형 ---> 수평 방향
        LinearLayout layout=new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);//수직
        layout.setOrientation(LinearLayout.HORIZONTAL);//수평
        layout.addView(tv);
        layout.addView(button);
        layout.addView(imageView);
        
       //  위쪽의 setContentView 다 주석해야 합니다. 
        setContentView(layout); 
        
    }
}