

In addition to using the Space class to create gaps, the spacing around views in cells can be controlled via the various margin layout properties (top, bottom, left and right) of each child. In the case of the GridLayout class, a Space view can be placed in any cell much like any other view object. This is a very simple class, the sole purpose of which is to create gaps within layouts. In addition, a child view of a GridLayout parent may also be configured to span multiple rows and columns through the use of the rowSpan and columnSpan properties of the child.Īnother useful class that can be used in conjunction with the GridLayout is the Space class. The gravity of a child view can, for example, be configured such that the view appears centered, fills the entire cell or is positioned in a specific corner of the cell within which it resides.

The positioning of a view within a cell can be defined through the use of gravity settings on that child view. Row and column numbering also starts at 0 beginning in the top left hand corner of the grid. The grid lines are referred to as indices, which are numbered starting at 0 for the line at the leading edge of the layout. The GridLayout essentially consists of a number of invisible horizontal and vertical grid lines that serve to divide the layout view into a series of rows and columns, with each intersecting row and column forming a cell which can, in turn, contain one or more views. The purpose of the GridLayout is to allow child views to be positioned in a grid arrangement. Introducing the Android GridLayout and Space Classes Directly creating GridLayout user interface designs using XML layout resources as an alternative to using the Designer tool will be covered in the next chapter, entitled Working with the Android GridLayout using XML Layout Resources. This chapter will introduce the basics of the GridLayout class before exploring the creation of a GridLayout-based user interface using Android Studio Designer.

Perhaps the easiest approach, however, is to make use of some GridLayout specific features built into the Android Studio Designer tool. There are a number of ways to implement the GridLayout within the user interface of an Android application, including through the use of layout resources and Java code. As the name suggests, this class allows child views to be arranged in a grid layout. Purchase the fully updated Android Studio Flamingo Edition of this publication in eBook ($29.99) or Print ($49.99) formatĪndroid Studio Flamingo Essentials - Java Edition Print and eBook (PDF) editions contain 88 chapters and over 800 pagesĪ useful layout manager that was introduced as part of the Android 4.0 SDK is the GridLayout manager class.

You are reading a sample chapter from the Android Studio 1.x / Android 6 Edition book.
