Skip to content
ZieIony edited this page Oct 25, 2019 · 1 revision

Android's view system is quite heavy and inflexible. Most of the views are very complex and do more things than you would need. For example, TextView is not just a simple text rendering tool. It also allows text editing, scrolling, highlighting (this is fine), adding images on four sides (wat?), handling padding, state and much more. Adding a custom view, that has to handle all of that is difficult and time-consuming.

Let's go through the things, you should implement, to make a complete custom view:

  • Constructors. You need at least the code constructor and the XML constructor.
  • Attributes and styles. Allow changing parameters from XML.
  • State saving.
  • Size measuring. Usually not applicable to layout-based views.
  • Listeners.
  • Sounds. Like clicking sound after the click event.
  • Accessibility. Make your custom view available to impaired users.

When implementing a custom view, you always have to think about the users. Not the users like in Google Play, but the programmers-users. Each custom view should do one thing, be flexible, styleable, performant/efficient, respect other views and work well on all APIs. Quite a task!