Creating custom view implementations
Sometimes, the existing widgets just aren't enough, no matter how much you customize them. Sometimes, you need to display something that simply isn't supported by the platform. In these cases, you might find yourself needing to implement your own custom widget. The View class can be easily extended to produce many different effects, but there are a few things that are worth knowing before you tackle it:
- The rendering for a
Viewis expected to happen in theonDrawmethod. - When rendering the graphics for the
View, you'll use aCanvasto send the drawing instructions. - Each
Viewis responsible for calculating the offsets for its padding, and by default, the graphics will be clipped to these dimensions. - You should avoid any object allocation (including arrays, if possible) in the
onDrawmethod. TheonDrawmethods are probably the most time-sensitive method calls in any application, and need to produce as little garbage as possible. Any object allocations should...