3.3.3. Arranging Views with LinearLayout and GridLayout

Recall that layouts arrange views in a GUI. A LinearLayout (package android.widget) arranges views either horizontally (the default) or vertically and can size its views proportionally. We’ll use this to arrange two TextViews horizontally and ensure that each uses half of the available horizontal space.

GridLayout (package android.widget) was introduced in Android 4.0 as a new layout for arranging views into cells in a rectangular grid. Cells can occupy multiple rows and columns, allowing for complex layouts. In many cases, GridLayout can be used to replace the older, and sometimes less efficient TableLayout, which arranges views into rows and columns where each row is typically defined ...

Get Android™ How to Program, 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.