自定义View中使用findViewById时返回NULL问题的
2019-08-27 本文已影响0人
手指乐
今天碰到一个findViewById查找自定义view时返回NULL的问题,经过排查发现是构造函数调用错误:
public QiuQianAnimationView(Context context, AttributeSet attrs) {
super(context);
}
QiuQianAnimationView这个自定义view中,调用父类的构造函数没有传入AttributeSet
改为:
public QiuQianAnimationView(Context context, AttributeSet attrs) {
super(context,attrs);
}
即可