“This is the 25th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”
GridLayout layout manager
The grid layout manager uses vertical and horizontal lines to divide the container into grids of n rows and m columns of equal size. One component is placed in each grid. Components added to the container are placed first in the grid in row 1, column 1 (upper left), and then the other components are placed from left to right in the grid in row 1. When the lines are full, continue placing the components left to right on the next line. Unlike FlowLayout, components placed in the GridLayout manager automatically occupy the entire area of the grid.
1. The GridLayout class is in the java.awt package
- A GridLayout allows the components of a container to be distributed in a regular grid that occupies the entire container space equally
3. When the size of the container changes, the size of the components in it changes too, but always occupies the same space in the container
4. Components in the GridLayout container always fill all the space of a block of the grid 5. Components are added in the main order of rows: the first row is the first, and the first row is the second…… The second line is the first……
GridLayout constructor
1. Public GridLayout(int Rows, int COLs) — A GridLayout object that creates rows cols columns with a default width of 5 pixels between rows
2. Public GridLayout(int Rows,int COLs,int hGap,int vGap) — Create a GridLayout object for cols columns of rows with hGAP and VGAP widths
The common construction of the GridLayout class is as follows:
1.GridLayout(): Build a GridLayout object, row by column.
GridLayout(int Rows, int COLs): Build a GridLayout object with the specified number of rows and columns.
GridLayout(int Rows, int COLs, int hGAP, int vgap): Specify the number of rows, columns, horizontal intervals, and vertical intervals to build a GridLayout object.
Conclusion:
1. Carry out the grid distribution of m rows and N columns of the container like a checkerboard
2. The height of each row (width of each column) of the grid is the same, equal to the height (width) of the container divided by the number of rows (columns) of the grid.
3. You cannot change the size of components, only the horizontal and vertical spacing between components
4. Components added to the container are placed from left to right
5. When the size of the container changes, the relative positions of each component remain unchanged and the size will change.
Points to note when using GridLayout:
GridLayout is a GridLayout that can’t be found in the minSDK version 14 or higher because GirdLayout was released after 4.0.
How to use GridLayout with the lower SDK:
The solution is simple: just import the GRIDLayout package for v7! The v7 package is available in the SDK: SDK \ Extras \ Android \support\v7\ Gridlayout directory. If you don’t have one, you can download it here: Gridlayout_v7_jay-rar.
<android.support.v7.widget.GridLayout>`
Copy the code