Chapter 2. Layouts

In this chapter, we will cover the following topics:

  • Defining and inflating a layout
  • Using RelativeLayout
  • Using LinearLayout
  • Creating tables – TableLayout and GridLayout
  • Using ListView, GridView, and Adapters
  • Changing layout properties during runtime
  • Optimizing layouts with the Hierarchy Viewer

Introduction

In Android, the User Interface is defined in a Layout. A layout can be declared in XML or created dynamically in code. (It's recommended to declare the layout in XML rather than in code to keep the presentation layer separate from the implementation layer.) A layout can define an individual ListItem, a fragment, or even the entire Activity. Layout files are stored in the /res/layout folder and referenced in code with the following ...

Get Android Application Development Cookbook - Second Edition 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.