Chapter 2. Views

In most graphical UI (GUI) frameworks, visual elements on the screen are represented by objects generally called “views” in architectural parlance. In web applications, a view might be an HTML element, but in some web frameworks a view is an entire web page, or a fragment of a page. Java Swing, and a number of other frameworks, use “components” to represent the view portion of the application.

In native mobile development, a view is exactly that—an instance of a View (Android) or UIView (iOS) subclass.

Views can be atomic elements and represent a single visual element on a screen, like a piece of text or an image, but might also be a more complicated hierarchy of views for layout, like a list of rows, or even more sophisticated, like a calendar widget with significant, sophisticated behavior built into the view itself.

Views are also necessary to receive user input. Buttons, switches and toggles, checkboxes, select boxes, and text inputs are all examples of views that enable your user to interact with your app.

Tasks

In this chapter, you’ll learn to:

  1. Create a new view.

  2. Nest views.

  3. Update a view’s state.

Android

In Android, the base class is View, and it is not abstract—you can instantiate a simple View where needed, although it may not be that common. One example is that sometimes simple View instances are used as lines or shapes, by simply providing dimensions and a background color, or as hit areas without visual representation. Some common examples ...

Get Native Mobile 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.