备注:
onMeasure:指定相关view的测量模式
onSizeChanged:获取相关尺寸参数
onFinishInflate:可以用来获取指定的view组件
code:
public class Demo extends View {
public Demo(Context context) {
super(context);
}
public Demo(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Demo(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
Log.d("Demo","onSizeChanged");
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.d("Demo","onMeasure");
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onFinishInflate() {
Log.d("Demo","onFinishInflate");
super.onFinishInflate();
}
@Override
protected void onDraw(Canvas canvas) {
Log.d("Demo","onDraw");
super.onDraw(canvas);
}
@Override
protected void onAttachedToWindow() {
Log.d("Demo","onAttachedToWindow");
super.onAttachedToWindow();
}
}
result:
onFinishInflate
Activity onCreate
Activity onStart
Activity onResume
onAttachedToWindow
onMeasure
onMeasure
onMeasure
onMeasure
onSizeChanged
onDraw
onMeasure
onMeasure
onDraw