回调方法与顺序
在View 的生命周期里有多个回调,在自定义view中有重要作用,了解方法用处及顺序是很有必要的
回调分类
createion 构造方法 onFinishInflate()
layout onMeasure(int,int) onlayou(boolean,int,int,int,int) onSizeChanged(int,int,int,int)
drawing onDraw(Canvas)
4.event processing onKeyUp(int,KeyEvent) onKeyDown(int,KeyEvent) onTouchEvent(MotionEvent) onTrackBallEvent(MotionEvent)
focus onFoucusChanged(boolean) onWindowFocusChanged(boolean)
Attaching onAttachedToWindow() onDetachedFromWindow() onWindowVisibilityChanged(int)
调用顺序
1.初始化顺序调用
顺序如下 构造方法 onFinishInflated() onAttachToWindow() onWindowVisibilityChanged() onMeasure()
onMeasure() // 注意onMeasure调用了两次 onSizeChanged(int,int,int,int) onLayout() onDraw()
onWindowFocusChanged()
退出activity 或者切换activity onWindowsFocusChanged() onWindowsVisibilityChanged() onDetachedFromWindow()
调用setVisibility(int)方法
设置不可见
无回掉方法
设置可见 onMeasure() onLayout() onDraw() ⤧ Next post Handler,Message,MessageQueue,Looper简析 ⤧ Previous post 自定义View基础绘制