October 2018
Intermediate to advanced
464 pages
15h 17m
English
We start by extending the View class, just as the built-in components do. Next, we create the default constructor. This is important as we need the context to pass down to the super class, which we do with the following call:
super(context);
We need to override onDraw(), otherwise, as mentioned in the Introduction, our custom view won't display anything. When onDraw() is called, the system passes in a Canvas object. The canvas is the screen area of our view. (Since we didn't override onMeasure(), our view would be 100 x 100, but since our entire activity consists of just this view, we get the whole screen as our canvas.)
We created the Paint object at the class level, and as final, to be more efficient with memory allocation. ...