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
View
is expected to happen in theonDraw
method. - When rendering the graphics for the
View
, you'll use aCanvas
to send the drawing instructions. - Each
View
is 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
onDraw
method. TheonDraw
methods are probably the most time-sensitive method calls in any application, and need to produce as little garbage as possible. Any object allocations should...