原因是代码写错了
public SnakeView(Context context, AttributeSet attrs) {
super(context, attrs);
initSnakeView();
}
public SnakeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initSnakeView();
}
构造函数中缺少上面红色代码,编译仍然通过,显示也正常,就是findViewById 返回null