Working with views

Though it is a bit cliché, it is true that views are the building blocks of the UI of an Android application. Activities, as we have seen, contain views, and View objects represent elements on the screen and are responsible for interacting with users through events.

Every Android screen contains a hierarchical tree of View elements. These views come in a variety of shapes and sizes. Many of the views you will need on a day-to-day basis are provided for you as part of the platform—basic text elements, input elements, images, buttons, and the like. In addition, you can create your own composite and/or custom views when the need arises. Views can be placed into an Activity (and thus on the screen) either directly in code or through the use of an XML resource that is later "inflated" at runtime.

In this section we will discuss fundamental aspects of views: the common views that Android provides, custom views that can be created as needed, layout in relation to views, and event handling. We won't address views defined in XML here, because that will be covered in section 3.3 as part of a larger resources discussion. Here we begin with the common View elements Android provides by taking a short tour of the API.

Download at Boykma.Com

0 0

Post a comment