When customizing view, the long time finally got it done.
When inheriting view, you want to implement all of its constructors.
Such as:
1 Public classHongdianextendsView {2 floatX=40;3 floatY=50;4Paint p =NewPaint ();5The construct to implement6 PublicHongdian (Context context) {7 Super(context);8 }9The constructor to implementTen PublicHongdian (Context context, @Nullable AttributeSet attrs) { One Super(context, attrs); A } -The constructor to implement - PublicHongdian (context context, @Nullable AttributeSet attrs,intdefstyleattr) { the Super(context, attrs, defstyleattr); - } -The constructor to implement - PublicHongdian (context context, @Nullable AttributeSet attrs,intDefstyleattr,intdefstyleres) { + Super(context, Attrs, defstyleattr, defstyleres); - } + A @Override at protected voidOnDraw (canvas canvas) { - Super. OnDraw (canvas); - P.setcolor (color.black); -Canvas.drawcircle (x,y,15, p); - } - in @Override - Public Booleanontouchevent (Motionevent event) { tox =event.getx (); +y =event.gety (); - This. Invalidate (); the return true; * } $}
Android Runtime exception: Binary XML file Line #: Error inflating class