In Android, View class is the base for widgets, which are used to create interactive UI components(Button, TextView, EditText,…). Android’s widgets are sufficient for the needs of most apps. However, there may be occasions on which you feel the need to implement a custom user interface for a project you are working on.
All of the view class defined in Android framework extend View. Our custom view can also extend View directly, or we can save time by extending one of the existing view subclasses, such as Button, TextView. We must understand View before we create a custom view.
What is View?
Same as above, View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.
So, what about Android View lifecycle?
To implement a custom view, my custom view class must extend Android View class. My custom view will begin by providing overrides for some of standard methods that the framework calls on all views. You do not need to override all of these methods. In fact, you can start by just overrideing onDraw(android.graphics.Canvas)
|Creation||Constructors||There is a form of the constructor that are called when the view is created from code and a form that is called when the view is inflated from a layout file. The second form should parse and apply any attributes defined in the layout file.|
|Called after a view and all of its children has been inflated from XML.|
|Layout||Called to determine the size requirements for this view and all of its children.|
|Called when this view should assign a size and position to all of its children.|
|Called when the size of this view has changed.|
|Drawing||Called when the view should render its content.|
|Event processing||Called when a new hardware key event occurs.|
|Called when a hardware key up event occurs.|
|Called when a trackball motion event occurs.|
|Called when a touch screen motion event occurs.|
|Focus||Called when the view gains or loses focus.|
|Called when the window containing the view gains or loses focus.|
|Attaching||Called when the view is attached to a window.|
|Called when the view is detached from its window.|
|Called when the visibility of the window containing the view has changed.|