안녕하세요 완전초보 한상이입니다 (__)
안드로이드 에뮬에서 제일 처음하는 "HelloWorld" 를 찍어보았는데요,
소스가 이해가 안가서 질문 드리게 되었습니다.
package net.npaka.helloworld;//(1)
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
//HelloWorld
public class HelloWorld extends Activity {//(2)(3)
@Override
public void onCreate(Bundle icicle) {//(4)
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);//(5)
setContentView(new HelloView(this));//(6)
}
}
package net.npaka.helloworld;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
//HelloWorld
public class HelloView extends View {//(7)
public HelloView(Context context) {
super(context);
setBackgroundColor(Color.WHITE);//(8)
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint=new Paint();//(9)
canvas.drawText("Hello World!",0,12,paint);//(10)
}
}
HelloWorld 에서 setContentView(new HelloView(this)) 이 구문에서 HelloView를 호출하는건 이해하는데
왜 호출하지 않은 onDraw()가 실행이 되는건가요? ;;;;




Drawing
Drawing is handled by walking the tree and rendering each view that intersects the the invalid region. Because the tree is traversed in-order, this means that parents will draw before (i.e., behind) their children, with siblings drawn in the order they appear in the tree. If you set a background drawable for a View, then the View will draw it for you before calling back to its
onDraw()method.Note that the framework will not draw views that are not in the invalid region.
To force a view to draw, call
invalidate().출처: http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)