3.4.3. Changing to a GridLayout

The default layout in activity_main.xml is a FrameLayout. Here, you’ll change that to a GridLayout. Right click the RelativeLayout in the Outline window and select Change Layout.... In the Change Layout dialog, select GridLayout and click OK. The IDE changes the layout and sets its Id to GridLayout1. We changed this to gridLayout using the Id field in the Properties window. By default, the GridLayout’s Orientation property is set to horizontal, indicating that its contents will be laid out row-by-row. Ensure that the GridLayout’s Padding Left and Padding Right properties are set to activity_horizontal_margin and that the Padding Top and Padding Bottom properties are set to activity_vertical_margin.

Specifying ...

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.