androidx / constraintlayout

ConstraintLayout is an Android layout component which allows you to position and size widgets in a flexible way
Apache License 2.0
1.07k stars 177 forks source link

[Grid] replace Guidelines with viewBoxes #622

Closed jswong65 closed 2 years ago

jswong65 commented 2 years ago

This PR does two things:

To make the Grid more flexible, viewBoxes (Views) are created to replace Guidelines for widgets to add constraints to. There are two main advantage of this approach:

  1. Only a less number of Views need to be created to arrange the widgets in the Grid.
  2. Offer the capability to create a nested Grid - (a Grid in another Grid)

The basic idea is that we create and place boxViews to constraint widgets. See the following figures for examples. Figure 1 shows how boxViews are created and rearranged for a 7 X 4 (rows X columns) Grid and Figure 2 shows an example of a 4 X 7 Grid.

The additional views needed to be created for the viewBox approach would be max(rows, columns). As for the Guideline approach, it would be (row - 1 + columns - 1).

Figure 1

Figure 2

jafu888 commented 2 years ago
  1. Remove Debug
  2. Remove HashMap<Integer, Pair<Integer, Integer>> type structures
  3. move to LayoutParams not Constraints
  4. change setters to "public void setXxxxxx(type value)"
  5. Gird should support 1x1 1xn nx1 Support 1xN Nx1 1x1 grids (It ask constraintSet for 1x1 gird)

    1. Support not setting grid_col:
      
      If grid_row and grid_col unspecified for n items make gird 
      grid_row = cel(sqrt(n))
      grid_col = cel(sqrt(n))

if only grid_row then grid_col = Math.cel(n/(float) grid_row) if only grid_col then grid_row = Math.cel(n/(float) grid_col) (this requires grid_row_specified and grid_col_specified flags so that if unspecified it will auto adapt) setRows(0) reset to grid_row_spefied=false setCol(0) reset to grid_col_spefied = false


7. Add grid debug flag  grid_debug="DESIGN_TIME|NEVER|ALWAYS" 
jafu888 commented 2 years ago

All other issues will be addressed in another PR