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 the onDraw method.
  • When rendering the graphics for the View, you'll use a Canvas 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.

Get Hands-On Android UI Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.