Constructing layout builders
So far in this book, all the layouts we have constructed have been static XML definitions. As you would expect, however, it is perfectly possible to construct and inflate UIs dynamically from our source code. Furthermore, Android layouts lend themselves very nicely to the builder pattern, as we saw with our alert dialog, as they are comprised of an ordered collection of smaller objects.
The following example will follow the builder design pattern to inflate a linear layout from a series of predefined layout views. As before, we will build up from interfaces to abstractions and concrete classes. We will create two kinds of layout item, a title or headline view and a content view. We then make several concrete examples ...
Get Android Design Patterns and Best Practice 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.