1.
onFinishInflate() 当View中所有的子控件均被映射成xml后触发
onMeasure(
int
,
int
) 确定所有子元素的大小
onLayout(
boolean
,
int
,
int
,
int
,
int
) 当View分配所有的子元素的大小和位置时触发
onSizeChanged(
int
,
int
,
int
,
int
) 当view的大小发生变化时触发
onDraw(Canvas) view渲染内容的细节
onKeyDown(
int
, KeyEvent) 有按键按下后触发
onKeyUp(
int
, KeyEvent) 有按键按下后弹起时触发
onTrackballEvent(MotionEvent) 轨迹球事件
onTouchEvent(MotionEvent) 触屏事件
onFocusChanged(
boolean
,
int
, Rect) 当View获取或失去焦点时触发
onWindowFocusChanged(
boolean
) 当窗口包含的view获取或失去焦点时触发
onAttachedToWindow() 当view被附着到一个窗口时触发
onDetachedFromWindow() 当view离开附着的窗口时触发,该方法和 onAttachedToWindow() 是相反。
onWindowVisibilityChanged(
int
) 当窗口中包含的可见的view发生变化时触发
2.
由 new GameView(context) 生成的View的回调顺序
LogUtils:GameView.onDetachedFromWindow(L:26)
LogUtils:GameView.<init>(L:14)
LogUtils:GameView.onAttachedToWindow(L:21)
LogUtils:GameView.onMeasure(L:55)
LogUtils:GameView.onSizeChanged(L:33)
LogUtils:GameView.onLayout(L:63)
LogUtils:GameView.onMeasure(L:55)
LogUtils:GameView.onLayout(L:63)
LogUtils:GameView.onDraw(L:47)
LogUtils:GameView.onMeasure(L:55)
LogUtils:GameView.onLayout(L:63)
由 xml文件生成的View的回调顺序
LogUtils:GameView.<init>(L:33)
LogUtils:GameView.onFinishInflate(L:61)
LogUtils:GameView.onAttachedToWindow(L:42)
LogUtils:GameView.onMeasure(L:76)
LogUtils:GameView.onSizeChanged(L:54)
LogUtils:GameView.onLayout(L:84)
LogUtils:GameView.onMeasure(L:76)
LogUtils:GameView.onLayout(L:84)
LogUtils:GameView.onDraw(L:68)
LogUtils:GameView.onMeasure(L:76)
LogUtils:GameView.onLayout(L:84)
package com.maintain; import lib.util.log.LogUtils; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.View; public class GameView extends View { public GameView(Context context) { super(context); LogUtils.d(null); } public GameView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); LogUtils.d(null); } public GameView(Context context, AttributeSet attrs) { super(context, attrs); LogUtils.d(null); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); LogUtils.d(null); } protected void onDetachedFromWindow() { LogUtils.d(null); }; @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); LogUtils.d(null); } @Override protected void onFinishInflate() { super.onFinishInflate(); LogUtils.d(null); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); LogUtils.d(null); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub super.onMeasure(widthMeasureSpec, heightMeasureSpec); LogUtils.d(null); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); LogUtils.d(null); } }