Home Tutorials Hints & Tips

Getting Started in Android Development

Part 18 - The Basic GridLayout

In this tutorial we will look at the basic grid layout. The grid layout was introduced in Android 4.0 (Ice Cream Sandwich). It provides a convenient tool for the construction a springboard menu. A springboard menu is a popular method of providing navigation within an app.  It comprises what can be described as images or images with text arranged as tiles on a screen that when touched will provide navigation though the app. Just like the home page of any Android phone or tablet.

The grid layout is generally a child layout. In the example for this tutorial the parent is a linear layout. Quite simply, the four image buttons are placed within the grid layout. Two attribute are added to the GridLayout. These define the row count and column count. The image buttons are then arranged in the order they are placed within the grid layout from top to bottom. Therefore, ib1 is displayed top left, ib2 top right, ib3 bottom left and ib4 bottom right. You will see from the screen shot below that all of the buttons are shown in the top left hand corner.

 Android layout with image buttons and basic gridlayout

To get a more desirable arrangement on the screen we need to use the XML “space” attribute with the image buttons. This is the subject of the next tutorial.

After this tutorial your activity_gridlayout.xml file should look similar to the one below. The GridLayoutActivity.java, ListviewActivity.java and Android Manifest files are unchanged from the last tutorial.

Download tutorial set 1

Privacy and Cookies Disclaimer Copyright
© 2015 - 2018 North Border Tech Training All rights reserved