标签:03 myfirstkotlin View1 自定义 Int 08 lixing 13501
class MyGeometryDraw @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : View(context, attrs, defStyleAttr) { override fun onFinishInflate() { super.onFinishInflate() Log.e("=========","onFinishInflate") } override fun onAttachedToWindow() { super.onAttachedToWindow() Log.e("=========","onAttachedToWindow") } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) Log.e("=========","onSizeChanged") } override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect) Log.e("=========","onFocusChanged") } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, heightMeasureSpec) Log.e("=========","onMeasure") } override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { super.onLayout(changed, left, top, right, bottom) Log.e("=========","onLayout") } override fun onDraw(canvas: Canvas?) { super.onDraw(canvas) Log.e("=========","onDraw") } override fun onDetachedFromWindow() { super.onDetachedFromWindow() Log.e("=========","onDetachedFromWindow") } }
启动执行方法顺序:
2021-03-08 10:54:23.929 13501-13501/com.lixing.myfirstkotlin E/=========: onFinishInflate
2021-03-08 10:54:24.002 13501-13501/com.lixing.myfirstkotlin E/=========: onAttachedToWindow
2021-03-08 10:54:24.007 13501-13501/com.lixing.myfirstkotlin E/=========: onMeasure
2021-03-08 10:54:24.007 13501-13501/com.lixing.myfirstkotlin E/=========: onMeasure
2021-03-08 10:54:24.260 13501-13501/com.lixing.myfirstkotlin E/=========: onMeasure
2021-03-08 10:54:24.260 13501-13501/com.lixing.myfirstkotlin E/=========: onMeasure
2021-03-08 10:54:24.261 13501-13501/com.lixing.myfirstkotlin E/=========: onSizeChanged
2021-03-08 10:54:24.261 13501-13501/com.lixing.myfirstkotlin E/=========: onLayout
2021-03-08 10:54:24.309 13501-13501/com.lixing.myfirstkotlin E/=========: onDraw
其中onMeasure会执行多次,不一定是四次
关闭后执行:
2021-03-08 11:06:29.237 13501-13501/com.lixing.myfirstkotlin E/=========: onDetachedFromWindow
标签:03,myfirstkotlin,View1,自定义,Int,08,lixing,13501 来源: https://blog.csdn.net/qq_34707150/article/details/114525887
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。