Changes

Jump to: navigation, search
no edit summary
<br><br>
A useful layout manager that was recently added to the Android SDK is the GridLayout manager class. As the name suggests, this class allows child views to be arranged in a grid layout. There are a number of ways to use the GridLayout within the user interface of an Android application, including through the use of layout resources and Java code. Perhaps the easiest approach, however, is to make use of some GridLayout specific features that have been added to the Graphical Layout tool.
For the purposes of this tutorial, the GridLayout is only required to be large enough to contain the child views contained therein. As such, the height and width parameters of the view need to be changed from match_parent to wrap_content. To make this change, select the layout, either by clicking on the white background of the user interface canvas, or from within the Outline panel. With the view selected, unfold the Layout Parameters section of the Properties panel and change the Width and Height values to wrap_content as illustrated in Figure 16-1:
[[Image:android_wrap_content.png|Changing the height and width properties of an Android GridLayout instance]]
Figure 16-1
[[Image:graphical_layout_gridlayout_buttons.png|Graphical Layout editor GridLayout buttons]]
Figure 16-2
[[Image:graphical_layout_gridlayout_remove_buttons.png|Graphical Layout editor GridLayout buttons when Grid Model Mode is enabled]]
Figure 16-3
[[Image:graphical_layout_gridlayout_snap_to_grid.png|Graphical Layout editor GridLayout buttons when Grid Model Mode is off]]
Figure 16-4
When enabled, a range of dots will appear in the layout to which views will snap when added to cells.
 
By far the most flexible way to manage the views in a GridLayout when using the Graphical Layout tool is to do so in Grid Model Mode with the Show Structure option enabled. With this in mind, make sure that these two modes are selected before proceeding to the next section.
[[Image:gridlayout_add_view_to_cell.png|Inserting a view into a GridLayout cell]]
Figure 16-5
[[Image:gridlayout_view_in_cell.png|A view added to the cell of a GridLayout]]
Figure 16-6
[[Image:gridlayout_shift_columns_right.png|Inserting a new column into an Android GridLayout]]
Figure 16-7
[[Image:gridlayout_two_rows.png|Inserting views into the cells second row of a GridLayout manager]]
Figure 16-8
[[Image:gridlayout_rowspan.png|Setting the rowSpan property on an Android GridLayout child]]
Figure 16-9
[[Image:gridlayout_gravity_settings.png|Android GridLayout child gravity settings]]
Figure 16-10
[[Image:gridlayout_cellspanning_center.png|GridLayout cell spanning with vertical center gravity]]
Figure 16-11
[[Image:gridlayout_cellspanning.png|A completed Android GridLayout example]]
Figure 16-12

Navigation menu