Description: The grid layout is added after 4.0 layout, with Tablelayout a bit like, but more useful, it divides the container into a rows*columns grid, each grid is a component bit, but by setting the component bit occupy more than one row/column.
Similarly, there is a component called the GridView, which is similar in function and name, but the GridView uses adapter to populate the component bits, and the GridLayout is much simpler.
According to Csdn Bo main studyboyjlu4 (blog address: http://blog.csdn.net/studyboyjlu4) View, The difference between the GridView and the GridLayout is similar to the difference between the ListView and the LinearLayout.
GridLayout has two types of properties to focus on:
1 properties of the GridLayout itself
Description: This type of property is set for GridLayout itself, primarily for rows and columns, and for the way it is set.
The attribute table is as follows:
Properties |
Correspondence Method |
Property Description |
Android:columncount |
Setcolumcount (int) |
Set the maximum number of columns for a layout |
Android:rowcount |
Setrowcount (int) |
Set the maximum number of rows for a layout |
Android:alignmentmode |
Setailgnmentmode (int) |
Set the layout to its way (alignbounds: to subassembly view boundary; Alignmargins: to subassembly view margins;) |
Android:columnorderpeserved |
Setcolumorderpreserved (Boolean) |
Set whether the container retains column ordinals |
Android:roworderpeserved |
Setroworderpeserved (Boolean) |
Sets whether the container retains row numbers |
Android:usedefaultmargins |
Setusedefaultmargins (Boolean) |
Sets whether the container uses the default page margins |
2 Properties for sub-components within a container
Description: This type of property is set for subcomponents in GridLayout, and you can set the size and placement of the component in the grid.
The attribute table is as follows:
Properties |
Correspondence Method |
Property Description |
Android:layout_gravity |
setgravity (int) |
Set how the component occupies the space of its owning grid |
Android:layout_column |
|
Set the component in the first column of the container |
Android:layout_row |
|
Set the component line in the container |
Android:layout_columnspan |
|
The Setup component occupies several columns |
Android:layout_rowspan |
|
The Setup component occupies a few lines |
The layoutgravity here is a bit different from the general layoutgravity, where the placement is relative to the owning mesh, not to the layout parent container.
<gridlayout android:columncount= "4" android:id= "@+id/root1" android:layout_width= "Fill_parent" Android:layo ut_height= "Fill_parent" > <imageview android:layout_rowspan= "2" android:layout_width= "100DP" android:layout_height= "200DP" android:background= "#600096"/> <imageview android:layout_columnspan= "2" android:layout_width= "200DP" android:layout_height= "100DP" android:background= "#006096"/> <imageview android:layout_rowspan= "2" android:layout_width= "100DP" android:layout_height= "50DP" android:layout_gravity= "Bottom" android:background= "#009660"/> <imageview Android:layout_colu Mnspan= "2" android:layout_rowspan= "2" android:layout_width= "200DP" android:layout_height= "300DP" android:background= "#960060"/> <imageview android:layout_width= "100DP" android:layout_height= "2 00DP "Android:background= "#AA6060"/> <imageview android:layout_width= "100DP" android:layout_height= "200DP" a Ndroid:background= "#AA55AA"/></gridlayout>
Attached: Citation statement
STUDYBOYJLU4 's Column: The difference between the GridLayout and the GridView
"Crazy Android Handout (second edition)" Li Gang "2.2.5 Android4.0 new Grid Layout" electronic industry Press
Android UI GridLayout (Grid layout)