自定义控件-继承ViewGrroup

来源:互联网 发布:opta数据中文 编辑:程序博客网 时间:2024/06/06 20:22
#自定义控件——继承ViewGroup
##常用方法总结
###1.两个参数的初始化构造函数,解析自定义控件的xml时调用创建对象
###2. onFinishInflate()
       自定义控件的xml解析完调用,此时子控件都已添加完毕,可以在这个方法里用getChildCount()
       和getChildAt(int index)得到子控件,并设置事件监听
###3.onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    测量自己和子控件的宽高
    调用如下两个方法
    measureChildren(widthMeasureSpec, heightMeasureSpec);
    改写super.onMeasure()方法中调用的getDefaultSize方法,根据xml文件中的设置得到控件的宽高
    setMeasuredDimension(measuredWidth, measuredHeight);
###4.onLayout(boolean changed, int l, int t, int r, int b)
    layout(l, t, r, b );对子控件进行布局
0 0
原创粉丝点击