View
is the parent class of ViewGroup, which is the base for all layouts.Sometimes, the existing View subclasses are insufficient, and you need to create a custom View. In general, to do this you need to:
- Inherit from View or a subclass of View (e.g., Button);
- Override the View class constructors. Constructors are used by the system when creating a View described in an XML layout, so it is necessary to override them even if they are not explicitly called;
- Create new or override existing event listener methods, such as onTouchEvent();
- Override the onDraw() and onMeasure() methods;
- Override other
on…
methods if necessary.
This list of actions is not mandatory but shows what is most often required to create a custom View.