标签:自定义view
onFinishInflate()函数的调用时机:
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发生变化时触发
另外,今天写了一个自定义View 的demo, 然后再布局文件中 使用完整包名 引用,但是一运行程序就报错,提示
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.qiquan.demo_customview.view.CustomView
经查询,原因是自定义View的类中需要重写三个构造方法,而我只重写了一个,
/**
*代码创建时调用
* Simple constructor to use when creating a view from code
* @param context
*/
public CustomView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/**
*布局文件加载时调用
* Constructor that is called when inflating a view from XML
* @param context
* @param attrs
*/
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
/**
* Perform inflation from XML and apply a class-specific base style
* @param context
* @param attrs
* @param defStyle
*/
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
标签:自定义view
原文地址:http://blog.csdn.net/daiqiquan/article/details/42920959